7-43 阅览室
很快打完 进步了 还有就是读懂题意 之前混淆了弄了很久
#include<iostream> #include<cstring> #include <bits/stdc++.h> using namespace std; int main(){ int n;cin>>n; for(int i=1;i<=n;i++) { int a[1000][2]={0};int sum=0;int ren=0; for(;;) { int num,time1,time2; char f; cin>>num>>f; scanf("%d:%d",&time1,&time2); int time=time1*60+time2; if(num==0)break; if(f=='S'){a[num][1]=1;a[num][0]=time;} if(f=='E'&&a[num][1]==1) {ren++;sum+=time-a[num][0];a[num][1]=0;} } if(sum%2==1)sum++; if(ren)printf("%d %d ",ren,(sum)/ren); else printf("0 0 "); } return 0; }
7-45 整除光棍
一开始模拟 位数不够 后来两个点过不了
#include<iostream> #include<cstring> #include <bits/stdc++.h> using namespace std; int main(){ int x;cin>>x; int n=0;int ans=0; while(1) { ans=ans*10+1;n++; if(ans>=x){ans%=x;} if(ans%x==0)break; } unsigned long long t=1; for(int i=1;i<n;i++) t=t*10+1; printf("%lld %d",t/x,n); return 0; }
然后边模拟边打印
虽然模拟的不太熟练 多打几次 输出整除 求余继续 一开始不能有0;
#include<iostream> #include<cstring> #include <bits/stdc++.h> using namespace std; int main(){ int x;cin>>x; int n=0;int ans=0; int key; int first=0; while(1) { ans=ans*10+1;n++; if(ans>=x){first=1;printf("%d",ans/x);ans%=x;} else if(first)printf("0"); if(ans==0){break;} } printf(" %d",n); return 0; }
点赞狂魔
用set很简单
7-50 重排链表
还是有一个点出错 搞不懂
#include <bits/stdc++.h> using namespace std; struct node { int x; int next; }a[100005]; int main() { int head,n; cin>>head>>n; int k=n; while(k--) { int num,x1,add; cin>>num>>x1>>add; a[num].x=x1; a[num].next=add; } int a1[100005],a2[100005]; a1[0]=head; for(int i=1;i<n;i++) { a1[i]=a[a1[i-1]].next; } a2[0]=a1[n-1]; int c1=0;int c2=n-1; for(int i=1;i<n;i++) { if(i%2==1) { a[ a2[i-1] ].next=a1[c1]; a2[i]=a1[c1];c1++; } else { a[ a2[i-1] ].next=a1[c2-1]; a2[i]=a1[c2-1];c2--; } } for(int i=0;i<n-1;i++) { printf("%05d %d %05d ",a2[i],a[a2[i]].x,a[a2[i]].next); } printf("%05d %d -1",a2[n-1],a[a2[n-1]].x); return 0; }
说明给出了重复节点 莫名其妙!!!
#include <bits/stdc++.h> using namespace std; struct node { int x; int next; }a[100005]; int main() { int head,n; cin>>head>>n; int k=n; while(k--) { int num,x1,add; cin>>num>>x1>>add; a[num].x=x1; a[num].next=add; } int cnt=0; int a1[100005],a2[100005]; while(head != -1){ a1[cnt++] = head;//将地址重新进行排列 head = a[head].next; } int x = 0,l = 0,r = cnt - 1; while(l <= r){ if(l == r) a2[x++] = a1[l++]; else{ a2[x++] = a1[r--]; a2[x++] = a1[l++]; } } if(n==x){ for(int i=0;i<x-1;i++) { printf("%05d %d %05d ",a2[i],a[a2[i]].x,a2[i+1]); } printf("%05d %d -1 ",a2[x-1],a[a2[x-1]].x); } return 0; }