试题A 门牌制作
答案为624
#include#include using namespace std; int n=0; void Sub(int i){ do { if(i%10==2){ n++; } i/=10; }while(i!=0); } int main(){ for(int i=1;i<=2020;i++){ Sub(i); } cout< 试题B 既约分数
结果为2481215
#includeusing namespace std; int gcd(int a,int b) { if(a%b==0) return b; else return gcd(b,a%b); } int main() { int ans = 0; for(int i = 1; i <= 2020; i++) { for(int j = 1; j <= 2020; j++) { if(gcd(i,j)==1) { ans++; } } } cout << ans < 试题C 蛇形填数
结果为761
#includeusing namespace std; int main() { int n = 20; n = n*2-1; int ans = 0,sum = 0; for(int i = 1; i <=n ;i++) { sum+=i; } ans = (sum+sum-n+1)/2; cout << ans < 试题D 跑步锻炼
答案为8879
#includeusing namespace std; int run(int year) { return (year%400==0)||(year%4==0&&year%100!=0); } int main() { int monNum = 0,weekNum = 0,monWeek = 0,days = 0,ans = 0; int monDay[13] = {0,31,30,31,30,31,30,31,31,30,31,30,31}; for(int i = 2000; i <= 2020; i++) { if(run(i)) monDay[2] = 29; else monDay[2] = 28; for(int j = 1; j <= 12; j++) { if(i==2020&&j==10) break; monNum += 1; days+=monDay[j]; if((days+1)%7==3) { monWeek++; } } } weekNum += days/7; if(days%7>=3) weekNum++; //cout << days+1 << ends << weekNum < 试题E 七段码
答案为80
#includeusing namespace std; int d[8][8]={0}; int dp[8],cnt=-1; int dfs2(int i,int p[]){ int sum=0; for(int j=1;j<8;j++) if(d[i][j]==1&&p[j]==0&&dp[j]==1){ sum+=j; p[j]=1; sum+=dfs2(j,p); } return sum; } int dfs1(){ int p[8]={0}; for(int i=1;i<8;i++) if(dp[i]!=0){ p[i]=1; return i+dfs2(i,p); } } void csh(){ d[1][2]=d[2][1]=1; d[1][7]=d[7][1]=1; d[2][3]=d[3][2]=1; d[2][4]=d[4][2]=1; d[3][5]=d[5][3]=1; d[3][4]=d[4][3]=1; d[5][6]=d[6][5]=1; d[6][4]=d[4][6]=1; d[6][7]=d[7][6]=1; d[4][7]=d[7][4]=1; } int fax(int i){ if(i==8) { int sum=0; for(int j=1;j<8;j++) sum+=dp[j]*j; if(sum==dfs1()) cnt++; } else { dp[i]=0; fax(i+1); dp[i]=1; fax(i+1); } } int main() { csh(); fax(1); cout< 试题F 成绩统计
#includeint main() { int i,t,n,good=0,nice=0; scanf("%d",&n); for(i=0;i =60&&++good&&t>=85&&++nice); } printf("%.0f%%n%.0f%%",(float)good/n*100,(float)nice/n*100); } 试题G 回文日期
#includeint n,y,r,p[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},f=2; int run(int n) { if(!(n%4)&&n%100||!(n%400)) return 1; return 0; } int day(){ if(++r&&r==1+p[y]+(y==2?run(n):0)){ r=1; if(y++&&y==13){ n++; y=1; } } } int main() { scanf("%4d%2d%2d",&n,&y,&r); while(f){ int a[8]; day(); a[0]=n/1000;a[1]=n/100%10;a[2]=n/10%10;a[3]=n%10; a[4]=y/10;a[5]=y%10;a[6]=r/10;a[7]=r%10; if(f==2&&a[0]==a[7]&&a[1]==a[6]&&a[2]==a[5]&&a[3]==a[4]){ printf("%04d%02d%02dn",n,y,r); f--; } if(f==1&&a[0]!=a[1]&&a[0]==a[2]&&a[0]==a[5]&&a[0]==a[7]&&a[1]==a[3]&&a[1]==a[4]&&a[1]==a[6]){ printf("%04d%02d%02dn",n,y,r); f--; } } return 0; } 试题H 子串分值和
#include#include #include using namespace std; unordered_map map; //记录距离正在遍历字母的最近位置 int t1, t2; //以字母第i个字母结尾的所有字符串的分值和为nums[i] void init() { for (char ch = 'a'; ch <= 'z'; ch++) { map[ch] = -1; } } int main() { init(); string str; cin >> str; int n = str.size(); map[str[0]] = 0; t1 = 1; int ans = 1; for (int i = 1; i < n; i++) { t2 = t1 + i - map[str[i]]; map[str[i]] = i; t1 = t2; ans += t2; } cout << ans << endl; return 0; } 试题I 平面切分
#includeusing namespace std; struct xy{ float a,b; int q; }s[1000]; int main() { int i,n,j,cnt=1,t=0,k; struct xy p[100000]; cin>>n; for(i=0;i >s[i].a>>s[i].b; cnt++; for(j=0;j 试题J 字串排序
#include#include using namespace std; int i,j,k,n,cnt; int dp[500][500]={0}; int p[26]; int max1[26]; char s[100]={0}; int fax(int m,int t,int sum) { if(sum==n) { if(t>cnt) return 0; else if(t 0;t++) if(p[j]>max1[j]) return 0; else if(p[j]==max1[j]) continue; else if(p[j] 0;j--) max1[j]=p[j]; break; } } } for(i=1;i >n; for(k=2;k*(k-1)/2 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)