九度oj 专题整理 (模拟部分1)
来源:互联网 发布:400块一家收淘宝店铺 编辑:程序博客网 时间:2024/05/16 18:54
分类参考链接 点击打开链接
假期陆续刷了很多水题,觉得ACM只要能理解思路的代码都是水题,套路也是有的,不过我的水平也就停留在水题上了,随着面试日期的临近,反而今天有些不静心,就不如现在整理一下自己做过的水题吧,也免得眼高手低,现在看看自己当时写的代码,很多思路也让现在的自己吃惊。因为自己总是喜欢倒序做事,那就从每个专题的题目倒序来吧
模拟类型:1000 1001 1020 1031 1036 1038 1013 1014 1045 1046 1048 1050 1059 1060 1062 1063 1064 1065 1067 1068 1070 1075 1177 1179 1183 1186
题目:1186(简单来说,就是判断闰年)因为之前做过类似的题目,这个就不再写一遍了
题目 1 Maya Calendar 点击打开链接
题目2 打印月历 点击打开链接
1.Maya Calendar,这个题目如果先加上1,再去对月份和星期取余,换过各种方式,样例过了,却总WA,现在还不懂为什么,所以参照网上的,改成先取余后加了,
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<set>#include<map>#define LL long long#define PI acos(-1)#define exp 1e-9using namespace std;priority_queue <int, vector<int>, greater<int> > Q;char Haab[20][20]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan","pax", "koyab", "cumhu", "uayet"};char holly[20][20]={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};int main(){ //printf("%s",Haab[1]); int n; scanf("%d",&n); //printf("%d\n",n); int day,year; char month[10]; int sum[10000]; memset(sum,0,sizeof(sum)); for(int j=0; j<n; j++) { scanf("%d.%s %d",&day,month,&year); sum[j]+=year*365; for(int i=0; i<19; i++) { if(strcmp(Haab[i],month)==0) { sum[j]+=i*20; break; } } sum[j]+=day; //printf("%d.%s %d",day,month,year); } printf("%d\n",n); //printf("%.8lf\n",16/10); for(int k=0; k<n; k++) { int y=sum[k]/260; //printf("%d\n",sum[k]); int m=sum[k]%20; int d=sum[k]%13+1; printf("%d %s %d\n",d,holly[m],y); } return 0; }
2.打印月历
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#define exp 1e-6#define pi acos(-1.0)using namespace std;int m1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int m2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};bool judge(int year){ if(year%100==0) { if(year%400==0) { return true; } } else { if(year%4==0) { return true; } } return false;}int daynum(int year){ int day=0; for(int i=1900; i<year; i++) { if(judge(i)) { day+=366; } else { day+=365; } } return day;}int monthday(int year,int month){ int mday=0; if(judge(year)) { for(int i=0; i<month; i++) { mday+=m2[i]; } } else { for(int i=0; i<month; i++) { mday+=m1[i]; } } return mday;}int main(){ int year,month; while(~scanf("%d %d",&year,&month)) { int day=daynum(year); day+=monthday(year,month); printf("Sun Mon Tue Wed Thu Fri Sat\n"); int flag=0; int mod=day%7+1; for(int k=0; k<mod; k++) { printf(" "); flag++; } if(judge(year)) { for(int i=1; i<m2[month];i++) { printf("%3d ",i); flag++; if(flag%7==0) printf("\n"); } printf("%3d\n",m2[month]); } else { for(int i=1; i<m1[month];i++) { printf("%3d ",i); flag++; if(flag%7==0) printf("\n"); } printf("%3d\n",m1[month]); } // printf("%d\n",day%7); } return 0;}
题目1183:守形数
现在看上去的想法还可以,大概是钻了数很小的空子,不然别的思路呢?
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<set>#include<map>#define LL long long#define PI acos(-1)#define exp 1e-9using namespace std;priority_queue <int, vector<int>, greater<int> > Q; int main(){ int n,m,ans; while(~scanf("%d",&n)) { m=n*n; if(n<10) ans=m%10; else if(n<100) ans=m%100; else ans=m%1000; if(ans==n) printf("Yes!\n"); else printf("No!\n"); } return 0; }
题目1179:阶乘,
题目很简单,可能对于初学者来说,就是要注意阶乘数据类型要用long long 吧,还做过一个题目要用double,发现自己之前wa过两次,原来将n%2判断奇数偶数写成了n%1 = =
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<set>#include<map>#define LL long long#define PI acos(-1)#define exp 1e-9#define INF 0x7fffffffusing namespace std;priority_queue <int, vector<int>, greater<int> > Q;long long list[1010];int n;int fun(){ list[0]=1; for(int i=1; i<=n; i++) { list[i]=list[i-1]*i; //printf("%d\n",list[i]); } }int main(){ while(~scanf("%d",&n)) { fun(); LL ans=0,cnt=0; if(n%2) { for(int i=1; i<=n; i+=2) { ans+=list[i]; } for(int i=2; i<=n-1; i+=2) { cnt+=list[i]; } } else { for(int i=1; i<=n-1; i+=2) { ans+=list[i]; } for(int i=2; i<=n; i+=2) { cnt+=list[i]; } } printf("%lld %lld\n",ans,cnt); } return 0;}
太长了,三个题为单位续写吧,,
阅读全文
0 0
- 九度oj 专题整理 (模拟部分1)
- 九度oj 专题整理 (模拟部分2)
- 九度oj 专题整理(模拟部分3)
- 九度oj 专题整理(模拟部分4)
- 九度OJ 1014 排名 (模拟)
- 九度OJ 1177 查找 (模拟)
- 九度OJ 1179 阶乘(模拟)
- 九度OJ 打印日期 (模拟)
- 【九度OJ】1002【模拟】
- 【九度OJ】1010【模拟】
- 【九度OJ】1022【模拟】
- 【九度OJ】1036【模拟】
- 【九度OJ】1018【模拟】
- 【九度OJ】1048【模拟】
- 【九度OJ】1021【模拟】
- 【九度OJ】1032【模拟】
- 【九度OJ】1013【模拟】
- 九度OJ 1147:Jugs(罐子) (模拟、游戏)
- ES6 函数参数的默认值
- 深入了解JAVA可变长度的参数(Varargs)
- Pycharm中进行Python远程开发
- 101. Symmetric Tree
- http 请求头设置
- 九度oj 专题整理 (模拟部分1)
- telnet不是内部或外部命令
- cgic 中文文档
- python 异常 try-except句型
- mtk平台Camera应用的全屏分析
- JavaScript 函数、函数调用
- remove-duplicates-from-sorted-array
- android架构师技能图谱
- Myeclipse10 创建Maven项目有如下几种!