zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    让他人变得优秀是伟大
    年龄越大,离家越远
    秋天的叶子
    [短彩信]C#短彩信模块开发设计(2)——配置
    jquery实现网页二级菜单简单代码
    HTML页面做中间页跳转传递参数
    ToJson
    Button页面中的按钮
    SQLSERVER 18056 错误
    在桌面添加可拖动/点击的悬浮窗口
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/3647531.html
Copyright © 2011-2022 走看看