第一题:
#include <iostream> using namespace std; char word[10]; int cti(char a,char b){ return (a-'0')*10+b-'0'; } int main(){ int n; cin>>n; while(n--){ cin>>word; if(cti(word[0],word[1])>23) word[0] = '0'; if(cti(word[3],word[4])>59) word[3] = '0'; if(cti(word[6],word[7])>59) word[6] = '0'; cout<<word<<endl; } return 0; }第二题:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; char word[100][100]; char w[10]; int main(){ int n,m,t; cin>>t; while(t--){ scanf("%d%d",&n,&m); for(int i = 0;i < n; i++) scanf("%s",word[i]); scanf("%s",&w); int ans = 0; int len = strlen(w); for(int i = 0;i < n; i++){ for(int j = 0;j < m; j++){ int f1=1,f2=1,f3=1; for(int k = 0;k < len; k++){ if(i+k>=n || j+k>=m || word[i+k][j+k] != w[k]) f1 = 0; if(i+k>=n || word[i+k][j] != w[k]) f2 = 0; if(j+k>=m || word[i][j+k] != w[k]) f3 = 0; } ans += f1+f2+f3; } } cout<<ans<<endl; } return 0; }第三题:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define ll long long #define maxn 100007 ll timeT[maxn]; int val[maxn]; int cti(char a,char b){ return (a-'0')*10+b-'0'; } ll getTime(char*a,char*b){ ll ans1 = cti(a[8],a[9])*10000+cti(a[6],a[7])*1000000 +cti(a[3],a[4])+cti(a[0],a[1])*100; ll ans2 = cti(b[0],b[1])*10000+cti(b[3],b[4])*100+cti(b[6],b[7]); return ans1*1000000+ans2; } int getAns(ll t,int n){ //cout<<t<<" "<<n<<endl; int low = 0, high = n-1; while(low <= high){ int mid = (low+high)/2; if(timeT[mid] >= t) high = mid-1; else low = mid+1; } //cout<<low<<endl; if(timeT[low] > t){ if(low == 0) return 0; return val[low-1]; } if(low == n) low--; return val[low]; } int main(){ char w1[11],w2[11]; int n,m; while(cin>>n){ for(int i = 0;i < n; i++){ scanf("%s%s%d",w1,w2,&val[i]); timeT[i] = getTime(w1,w2); if(i) val[i] += val[i-1]; //cout<<time[i]<<endl; } scanf("%d",&m); for(int i = 0;i < m; i++){ scanf("%s%s",w1,w2); ll t1 = getTime(w1,w2); scanf("%s%s",w1,w2); ll t2 = getTime(w1,w2); //cout<<t1<<" "<<t2<<endl; //cout<<getAns(t2,n)<<" "<<getAns(t1-1,n)<<endl; int ans = getAns(t2,n)-getAns(t1-1,n); printf("%d\n",ans); } } return 0; }
第四题:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Node{ int hp,y; }; int getHarm(int ehp,int eatk,int atk,int cd,int x[]){ int p = 0; for(int i = 0;i < cd; i++){ if(i > 2) p += atk; else if(x[i] > atk) p += x[i]; else p += atk; } int h = 0; int r = ehp / p; h += r * cd * eatk; r = ehp - r * p; for(int i = 0;i < cd; i++){ if(r <= 0) break; h += eatk; if(i > 2) r -= atk; else if(x[i] > atk) r -= x[i]; else r -= atk; } return h; } void work(Node node[],int o1,int o2,int o3,int &ans,int hp,int atk,int cd,int x[]){ int k = 0; int h = 0; for(int i = 0;i < 3; i++) h+=node[i].y; k += getHarm(node[o1].hp,h,atk,cd,x); h -= node[o1].y; k += getHarm(node[o2].hp,h,atk,cd,x); h -= node[o2].y; k += getHarm(node[o3].hp,h,atk,cd,x); ans = min(ans,k); } int main(){ int t; cin>>t; while(t--){ int hp,atk,cd; int x[3]; Node node[3]; cin>>hp>>atk>>cd; for(int i = 0;i < 3; i++) cin>>x[i]; sort(x,x+3); swap(x[0],x[2]); for(int i = 0;i < 3; i++){ cin>>node[i].hp>>node[i].y; } int ans = hp; work(node,0,1,2,ans,hp,atk,cd,x); work(node,0,2,1,ans,hp,atk,cd,x); work(node,1,0,2,ans,hp,atk,cd,x); work(node,1,2,0,ans,hp,atk,cd,x); work(node,2,0,1,ans,hp,atk,cd,x); work(node,2,1,0,ans,hp,atk,cd,x); ans = hp - ans; if(ans == 0) ans = -1; cout<<ans<<endl; } return 0; }
第五题:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define maxn 100007 int getMin(int a,int b) { return a<b?a:b; } char word[170000]; void work(int lone,int lzero,int rone,int rzero,int &one,int &zero,int t){ if(t == 0){ //'|' if(lzero == -1 || rzero == -1) zero = -1; else zero = lzero + rzero; one = -1; if(lzero != -1 && rone != -1){ if(one == -1) one = lzero + rone; else one = getMin(one,lzero+rone); } if(lone != -1 && rzero != -1){ if(one == -1) one = lone + rzero; else one = getMin(one,lone+rzero); } if(lone != -1 && rone != -1){ if(one == -1) one = lone + rone; else one = getMin(one,lone+rone); } //cout<<"| one: "<<one<<endl; } else { if(lone == -1 || rone == -1) one = -1; else one = lone+rone; zero = -1; if(lzero != -1 && rone != -1){ if(zero == -1) zero = lzero + rone; else zero = getMin(zero,lzero+rone); } if(lone != -1 && rzero != -1){ if(zero == -1) zero = lone+rzero; else zero = getMin(zero,lone+rzero); } if(lzero != -1 && rzero != -1){ if(zero == -1) zero = lzero + rzero; else zero = getMin(zero,lzero+rzero); } //cout<<"& one: "<<one<<endl; } } int dfs(int l,int r,int &one,int &zero){ //cout<<l<<" "<<r<<endl; if(l == r){ if(word[l] == '0'){ one = -1; zero = 0; return 0; } else { one = 0; zero = -1; return 1; } } int mid , le = 0, ri = 0; l++,r--; int ll = l, rr = r; while(true){ if(le == 0 && (word[l] == '|' || word[l] == '&')){ mid = l; break; } if(ri == 0 && (word[r] == '|' || word[r] == '&')){ mid = r; break; } if(word[l] == '(') le++; if(word[l] == ')') le--; if(word[r] == ')') ri++; if(word[r] == '(') ri--; l++,r--; } int lo,lz,ro,rz; int ans1 = dfs(ll,mid-1,lo,lz); int ans2 = dfs(mid+1,rr,ro,rz); //cout<<lo<<" "<<lz<<" "<<ro<<" "<<rz<<endl; int t = 0; if(word[mid] == '&') t = 1; int y1,y2; work(lo,lz,ro,rz,y1,y2,t); //cout<<y1<<" "<<y2<<endl; int x1,x2; work(lo,lz,ro,rz,x1,x2,!t); one = y1, zero = y2; if(x1 != -1) x1++; if(x2 != -1) x2++; //cout<<one<<" "<<zero<<" "<<x1<<" "<<x2<<endl; if(one == -1) one = x1; else if(x1 != -1) one = min(one,x1); if(zero == -1) zero = x2; else if(x2 != -1) zero = min(zero,x2); //if(one < 0) one = -1; //if(zero < 0) zero = -1; //cout<<one<<" === "<<zero<<endl; //cout<<ans1<<word[mid]<<ans2<<endl; if(t == 0) return ans1 | ans2; else return ans1&ans2; } int main(){ int t; scanf("%d",&t); while(t--){ scanf("%s",word); int len = strlen(word); int l[2]; int ans = dfs(0,len-1,l[1],l[0]); cout<<ans<<" "<<l[!ans]<<endl; } return 0; }