ZOJ 3326 An Awful Problem 模拟

只有在 Month 和 Day 都为素数的时候才能得到糖

那就模拟一遍时间即可.

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0)

using namespace std;

typedef long long           ll      ;
typedef unsigned long long  ull     ;
typedef unsigned int        uint    ;
typedef unsigned char       uchar   ;

template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;}

const double eps = 1e-7      ;
const int N = 210            ;
const int M = 1100011*2      ;
const ll P = 10000000097ll   ;
const int MAXN = 10900000    ;

int month1[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool run (int x) {
    if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0) return true;
    return false;
}

bool prime (int num){
    if (num == 1)    return false;
    for (int i = 2; i <= sqrt(num); ++i){
        if (num % i == 0)    return false;
    }
    return true;
}

int main() {
    std::ios::sync_with_stdio(false);
    int i, j, t, k, u, v, numCase = 0;
    int y1, y2, m1, m2, d1, d2;
    cin >> t;
    while (t--) {
        cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
        int ans = 0;
        while (y1 < y2) {
            if (!run (y1)){
                for (; m1 <= 12; ++m1) {
                    for (; d1 <= month1[m1]; ++d1){
                        if (prime(m1) && prime(d1))   ++ans;
                    }
                    d1 = 1;
                }
            } else{
                for (; m1 <= 12; ++m1) {
                    for (; d1 <= month2[m1]; ++d1) {
                        if (prime(m1) && prime(d1))   ++ans;
                    }
                    d1 = 1;
                }
            }
            m1 = 1;
            ++y1;
        }
        if (!run (y1)) {
            for (; m1 < m2; ++m1) {
                for (; d1 <= month1[m1]; ++d1) {
                    if (prime(m1) && prime(d1))   ++ans;
                }
                d1 = 1;
            }
            for (; d1 <= d2; ++d1) {
                if (prime(m2) && prime(d1))   ++ans;
            }
        } else{
            for (; m1 < m2; ++m1) {
                for (; d1 <= month2[m1]; ++d1) {
                    if(prime(m1) && prime(d1))   ++ans;
                }
                d1 = 1;
            }
            for (; d1 <= d2; ++d1) {
                if(prime(m2) && prime(d1))   ++ans;
            }
        }
        cout << ans << endl;
    }

    return 0;
}
时间: 2024-10-12 11:34:59

ZOJ 3326 An Awful Problem 模拟的相关文章

ZOJ 3326 An Awful Problem (较清晰写法,附详细注解)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3326 题面: An Awful Problem Time Limit: 1 Second      Memory Limit: 32768 KB In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of the month w

zoj3326An Awful Problem

题目链接: 点我点我 题目: An Awful Problem Time Limit: 1 Second      Memory Limit: 32768 KB In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of the month was a prime number. Hiqivenfin was happy with that. But sever

HDU 4974 A simple water problem 模拟(水

水题. #include <cstdio> #include <iostream> #include <queue> #include <algorithm> using namespace std; typedef long long ll; priority_queue<int> q; int main() { int T, cas = 0; scanf("%d", &T); while(T-- > 0) {

ZOJ 1111 Poker Hands --复杂模拟

昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽. 题意:玩扑克,比大小.规则如下: 题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从高到低依次为:1.同花顺:牌面一样,只比较最大的看谁大,一样大则平手2.四条:四个一样的,看这四个一样的中谁大谁赢3.葫芦:三条+一对,看三条中谁的牌面大4.同花:都是同花就按从大到小比较,看谁的更大5.顺子:都是顺子看最大的谁大,一样则平手6.三条:三条看三条中谁的牌面大7.两对: 两对就看谁的对

Codeforces 30D King&#39;s Problem? 模拟

首先将n个点排序,找出排序后的K,然后分情况讨论. 当 k == n+1时,显然是 k->1->n || k->n->1这两种的较小值,因为三角形的两边之和大于第三边. 当1 <= k && k <= n 时: 1 , k -> 1 -> n+1 -> k+1 ->n  ||  k -> n -> n+1 -> k-1 -> 1,当k+1 || k-1 不存在时将对应步骤忽略. 2 , k - > 1

ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树)

题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. 所以开$48$棵线段树,和一个永久标记.当对某个区间操作时对这个区间加一层永久标记. 即当前我要查找的第$x$层,实际找的是第$up[i] + x$层. 时间复杂度$O(48nlogn)$ #include <bits/stdc++.h> using namespace std; #define

zoj 3818 Pretty Poem (模拟)

ZOJ Problem Set - 3818 Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM

ZOJ 1457 Prime Ring Problem(dfs+剪枝)

?? Prime Ring Problem Time Limit: 10 Seconds      Memory Limit: 32768 KB A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime

hdu_5832_A water problem(模拟)

题目链接:hdu_5832_A water problem 这是一个惨痛的教训,想这种这么大的大数肯定就是找个规律模拟一下. 然而我们队还写JAVA,用大数艹了13发罚时,真是TM智障了. 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int N=1e7+7; 5 char a[N];int x,ic=1; 6 7 int main() 8 { 9 while(~scanf("%s",a)) 10 {