标签:include name algorithm 大学 集合 while 输入 col 表示
多组输入 每组数据第一行输入n,m(1<=n,m<=1000),n表示年轮广场上位置的个数,m表示Mathon以及他的小伙伴总人数 第二行m个数,第i个A[i](1<=A[i]<=n)表示第i个人的位置。
每组数据输出一行,表示所需要的最少时间。
5 3 1 4 5 3 2 1 3
1 1
第一组数据选择5为集合地点,第二组数据选择2为集合地点。
这个题我本来想的是直接绝对值就行,打完发现错了,还是分情况讨论了下
#include <stdio.h> #include <algorithm> using namespace std; int a[1005]; int main() { int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=0;i<m;i++) scanf("%d",&a[i]); int mi=1<<30; for(int i=1;i<=n;i++) { int s=0; for(int j=0;j<m;j++) { int b; if(a[j]>i) b=min(a[j]-i,n-a[j]+i); else b=min(i-a[j],n+a[j]-i); s=max(b,s); } if(s<mi)mi=s; } printf("%d\n",mi); } return 0; }
多组输入 每组输入一行,有3个数字y,m,x(1000<=y<=3000,1<=m<=12,0<=x<=9),分别代表年份,月份,和他想知道哪个数字出现的次数。
每组输出一个整数,表示数字x在这个月的日期里出现了多少次。
2017 4 4 2000 1 0
33 我也不知道,2333
第一组样例中,日中有数字4的为2017-04-04,2017-04-14,2017-04-24,4月一共有30天,因为月份中有4,所以数字4一共出现了30 + 3 = 33次
直接就可以水过了,就是可能判断闰年长时间不写感觉有点复杂
#include<bits/stdc++.h> using namespace std; int mon[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; int x; int la(int n) { int l=0,cnt=0; while(n) { l++; if(n%10==x)cnt++; n/=10; } if(l==1&&x==0)cnt++; return cnt; } int main() { int n,m; while(~scanf("%d%d%d",&n,&m,&x)) { int ans=0; if(n%4==0&&n%100!=0||n%400==0)mon[2]=29; for(int i=1; i<=mon[m]; i++) { ans+=la(n)+la(m)+la(i); } mon[2]=28; printf("%d\n",ans); } return 0; }
其他题待补
标签:include name algorithm 大学 集合 while 输入 col 表示
原文地址:http://www.cnblogs.com/BobHuang/p/7471065.html