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- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; int month1[] = {, , , , , , , , , , , , };
int month2[] = {, , , , , , , , , , , , }; bool run (int x) {
if (x % == && x % != || x % == ) return true;
return false;
} bool prime (int num){
if (num == ) return false;
for (int i = ; i <= sqrt(num); ++i){
if (num % i == ) return false;
}
return true;
} int main() {
std::ios::sync_with_stdio(false);
int i, j, t, k, u, v, numCase = ;
int y1, y2, m1, m2, d1, d2;
cin >> t;
while (t--) {
cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
int ans = ;
while (y1 < y2) {
if (!run (y1)){
for (; m1 <= ; ++m1) {
for (; d1 <= month1[m1]; ++d1){
if (prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
} else{
for (; m1 <= ; ++m1) {
for (; d1 <= month2[m1]; ++d1) {
if (prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
}
m1 = ;
++y1;
}
if (!run (y1)) {
for (; m1 < m2; ++m1) {
for (; d1 <= month1[m1]; ++d1) {
if (prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
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 = ;
}
for (; d1 <= d2; ++d1) {
if(prime(m2) && prime(d1)) ++ans;
}
}
cout << ans << endl;
} return ;
}
ZOJ 3326 An Awful Problem 模拟的更多相关文章
- ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...
- ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)
题目链接 ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...
- ZOJ 2392 The Counting Problem(模拟)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1368 题目大意:计算从S到T中所有的数,其中0,1,2,3,4,5, ...
- UVALive 3486/zoj 2615 Cells(栈模拟dfs)
这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...
- hdu_5832_A water problem(模拟)
题目链接:hdu_5832_A water problem 这是一个惨痛的教训,想这种这么大的大数肯定就是找个规律模拟一下. 然而我们队还写JAVA,用大数艹了13发罚时,真是TM智障了. #incl ...
- 详解OJ(Online Judge)中PHP代码的提交方法及要点【举例:ZOJ 1001 (A + B Problem)】
详解OJ(Online Judge)中PHP代码的提交方法及要点 Introduction of How to submit PHP code to Online Judge Systems Int ...
- ZOJ 1457 Prime Ring Problem(dfs+剪枝)
Prime Ring Problem Time Limit: 10 Seconds Memory Limit: 32768 KB A ring is compose of n circ ...
- 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...
- ZOJ 1001 A + B Problem
熟悉ZOJ环境,如何上传代码,如何查看结果. #include<iostream> using namespace std; int main(){ int a,b; while(cin& ...
随机推荐
- IOS 表视图(UITableVIew)的使用方法(4)自定义表视图单元
UITableViewCell的自定义往往需要自建一个UITableViewCell的子类后进行作业.开发者可以选择通过xib或者直接在UITableViewCell的布局中进行UITableView ...
- 未能加载文件或程序集“xxxx”或它的某一个依赖项
一般是解决方案中相互依赖的项目生成的目标平台不一样所致,更改为相同目标即可!
- 定时每天备份mysql
http://blog.csdn.net/panning_hu/article/details/9210001 Spring MVC Spring中MVC框架的底层实现 http://blog.csd ...
- 从51跳新唐cortex-m0学习1——思想转变
Cortex-M0学习第一帖 序言:这里先说一下,大家在看帖子时候,可能看见字数比较多的,可能只是先大概浏览一下,之后从中挑几段大概瞅瞅,但是我要说,如果你碰到一个适合的帖子,请仔细品读,这是我在论坛 ...
- C#实现阻止关闭显示器和系统待机
原文http://www.cnblogs.com/TianFang/archive/2012/10/12/2721883.html 最近写了一个下载程序,发现有一个问题:挂机下载的时候,下载任务会因为 ...
- linux 的 ping 原理
ping命令的工作原理是: ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具. 他向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文原样传回给发送者,这 ...
- Hello China操作系统STM32移植指南(一)
Hello China操作系统移植指南 首先说明一下,为了适应更多的文化背景,对Hello China操作系统的名字做了修改,修改为"Hello X",或者连接在一起,写为&quo ...
- 如何用python抓取js生成的数据 - SegmentFault
如何用python抓取js生成的数据 - SegmentFault 如何用python抓取js生成的数据 1赞 踩 收藏 想写一个爬虫,但是需要抓去的的数据是js生成的,在源代码里看不到,要怎么才能抓 ...
- JavaScript推断E-mail地址是否合法
编写自己定义的JavaScript函数checkEmail(),在该函数中首先推断E-mail文本框是否为空,然后在应用正則表達式推断E-mail地址是否合法,假设不合法提示用户 <script ...
- VCS引起的oracle数据库异常重新启动一例
1. 环境描写叙述 操作系统版本号:SUSE Linux Enterprise Server 10 sp2 (x86_64) 数据库版本号:Oracle 11.1.0.7.16 VCS版本号:5.1 ...