洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
来源:互联网 发布:飞天侠淘宝客系统8.0 编辑:程序博客网 时间:2024/06/05 07:25
题目:
https://www.luogu.org/problem/show?pid=1202
在洛谷,这个题只有入门难度;
但我调了两个多小时;
主要原因在于我只是用gdb调试和用肉眼看;
而对于这种题,最好的调试方法是输出中间变量;
适当的标识汉字有利于调试;
我并不觉得做简单题是在消磨时间;
相反,A掉这道题,我很开心,甚至比做出理论上比这难几十倍的题后更开心;
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,num,cnt[12];int a[1001][13];int ss=0;bool pdnian(int x){ if(!(x%100)) { if(!(x%400)) return true; else return false; } else { if(!(x%4)) return true; else return false; }}void ji(int x){ int tot=x-1900; a[tot][4]=a[tot][6]=a[tot][9]=a[tot][11]=30; if(pdnian(x)) a[tot][2]=29; else a[tot][2]=28; a[tot][1]=a[tot][3]=a[tot][5]=a[tot][7]=a[tot][8]=a[tot][10]=a[tot][12]=31; return;}void solve(){ scanf("%d",&n); for(int i=1900;i<=1900+n-1;i++) { ji(i);// cout<<i<<" ";// for(int j=1;j<=12;j++) cout<<a[i-1900][j]<<" ";// cout<<endl; } //预处理出天数,及是否是闰年; num=1;//第一天是星期一; for(int i=1900;i<=1900+n-1;i++) { int x=i-1900;//获取当前的年数; for(int j=1;j<=12;j++) { ss=a[x][j]; // cout<<"年份 :"<<i<<" 月份:"<<j<<" 第一天星期 :"<<num; int c=(num+12)%7; cnt[c]++; num=(num+ss)%7; // cout<<" 十三号星期"<<c<<" 有"<<ss<<"天"<<endl; } } cout<<cnt[6]<<" "; for(int i=0;i<=5;i++) cout<<cnt[i]<<" "; return;}int main(){ solve(); return 0;}
阅读全文
1 0
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- [USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
- 【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 【USACO1.1_3】★Friday the Thirteenth 黑色星期五
- usaco1.1.3 Friday the Thirteenth黑色星期五
- USACO1.1.3 Friday the Thirteenth(黑色星期五)
- [USACO1.1]Friday the Thirteenth
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth 黑色星期五
- USACO1.1 Friday the Thirteenth 比较分析
- Friday the Thirteenth(黑色星期五) USACO
- USACO1.1.3[Friday The Thirteenth]
- USACO1.1.3 Friday the Thirteenth
- USACO1.1.3 - Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth
- VMware Fusion安装mini版Centos正确流程及错误示范
- 数据交互时中文乱码问题的解决方法总结
- Codeforces452F(MemSQL Start[c]UP 2.0)[Permutation]--线段树+Hash
- 批量提取文件名的经典方法
- hdu4496(并查集+逆向思维)
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- android图片加载框架-磁盘缓存
- Mysql得到某个表的所有字段
- 关于QT 内存泄露
- 数据结构的概念和学习数据结构的必要性
- 携程移动端架构演进与优化之路
- Kettle—配置及使用
- MapReduce实现QQ好友推荐
- JavaScript的Math对象