https://vjudge.net/contest/285902#overview
A.Marjar Cola
#include <bits/stdc++.h> using namespace std; int T; int main() { scanf("%d", &T); while(T --) { int x, y, a, b; int ans = 0; scanf("%d%d%d%d", &x, &y, &a, &b); if(x == 1 || y == 1 || (x == 2 && y == 2 && a == 2) ||(x == 2 && y == 2 && b == 2)) { printf("INF\n"); continue; } while(1) { if(a < x && b < y) break; int num1 = a / x; int num2 = b / y; ans += (num1 + num2); a = a - num1 * x + num1 + num2; b = b - num2 * y + num1 + num2; } printf("%d\n", ans); } return 0; }
C.How many Nines
#include <bits/stdc++.h> using namespace std; int dp[10005][13][33]; int date[13]={0,31,0,31,30,31,30,31,31,30,31,30,31}; int cal(int x) { if(x%400==0||(x%4==0&&x%100!=0)) return 29; else return 28; } int check(int x,int y,int z) { int ans=0; while(x) { if(x%10==9) ans++; x/=10; } while(y) { if(y%10==9) ans++; y/=10; } while(z) { if(z%10==9) ans++; z/=10; } return ans; } int find_last(int x,int y,int z) { if(z!=1) return dp[x][y][z-1]; int day=date[y-1]; if(y==3) day=cal(x); if(y!=1) return dp[x][y-1][day]; return dp[x-1][12][31]; } int main() { for(int i=2000;i<=9999;i++) { int last_day; for(int j=1;j<=12;j++) { int day=date[j]; if(j==2) day=cal(i); for(int k=1;k<=day;k++) { dp[i][j][k]=check(i,j,k); if(k!=1) dp[i][j][k]+=dp[i][j][k-1]; else if(j!=1) dp[i][j][k]+=dp[i][j-1][last_day]; else dp[i][j][k]+=dp[i-1][12][31]; } last_day=day; } } int T;scanf("%d",&T); while(T--) { int x1,y1,z1,x2,y2,z2; scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2); printf("%d\n",dp[x2][y2][z2]-find_last(x1,y1,z1)); } }
F.Intervals
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int T; struct Node{ int l; int r; int num; }node[maxn], n[maxn]; bool cmp(const Node &a, const Node &b) { if(a.l != b.l) return a.l < b.l; else return a.r < b.r; } bool cmpp(const Node &a, const Node &b) { return a.r > b.r; } bool isin(const Node &a, const Node &b, const Node &c) { if(a.r >= b.l && b.r >= c.l && a.r >= c.l) return true; return false; } int main() { scanf("%d", &T); while(T --) { int N; scanf("%d", &N); for(int i = 1; i <= N; i ++) { scanf("%d%d", &node[i].l, &node[i].r); node[i].num = i; } vector<int> ans; sort(node + 1, node + 1 + N, cmp); n[1] = node[1], n[2] = node[2]; for(int i = 3; i <= N; i ++) { n[3] = node[i]; sort(n + 1, n + 1 + 3, cmp); if(isin(n[1], n[2], n[3])) { sort(n + 1, n + 1 + 3, cmpp); ans.push_back(n[1].num); swap(n[1], n[3]); } else sort(n + 1, n + 3 + 1, cmpp); } sort(ans.begin(), ans.end()); printf("%d\n", ans.size()); for(int i = 0; i < ans.size(); i ++) printf("%d%s", ans[i], i != ans.size() - 1 ? " " : "\n"); } return 0; }
G.Seven-Segment Display
#include<bits/stdc++.h> using namespace std; const int maxn=5500; bitset<maxn>G[130][10],ans; int t[9]; bool vis[9]; void work(int P) { for(int i=0;i<(1<<7);i++) { memset(vis,0,sizeof(vis)); for(int k=0;k<7;k++) if(!(i>>k&1)) vis[t[k]]=1; if(vis[1]&&vis[2]) G[i][1][P]=1; if(vis[0]&&vis[1]&&vis[6]&&vis[4]&&vis[3]) G[i][2][P]=1; if(vis[0]&&vis[1]&&vis[6]&&vis[2]&&vis[3]) G[i][3][P]=1; if(vis[1]&&vis[5]&&vis[6]&&vis[2]) G[i][4][P]=1; if(vis[0]&&vis[5]&&vis[6]&&vis[2]&&vis[3]) G[i][5][P]=1; if(vis[0]&&vis[5]&&vis[6]&&vis[4]&&vis[2]&&vis[3]) G[i][6][P]=1; if(vis[0]&&vis[1]&&vis[2]) G[i][7][P]=1; if(vis[0]&&vis[1]&&vis[2]&&vis[3]&&vis[4]&&vis[5]&&vis[6]) G[i][8][P]=1; if(vis[0]&&vis[1]&&vis[2]&&vis[3]&&vis[5]&&vis[6]) G[i][9][P]=1; } } int main() { for(int i=0;i<7;i++) t[i]=i; int k=0; do { work(k); k++; }while(next_permutation(t,t+7)); int T;scanf("%d",&T); while(T--) { ans.set(); int n;scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&k); int x=0;char str[9];scanf("%s",&str); for(int j=0;j<7;j++) x=x*2+str[j]-‘0‘; ans&=G[x][k]; } if(ans.any()) printf("YES\n"); else printf("NO\n"); } }
H.Saddle Points
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int t[1005][1005],p[1005][1005],tmp[1005],kp[2005]; struct node { int id,val; }b[1005]; bool cmp1(const node &A,const node &B) { return A.val>B.val; } bool cmp2(const node &A,const node &B) { return A.val<B.val; } int main() { kp[0]=1; for(int i=1;i<2005;i++) kp[i]=kp[i-1]*2%mod; int T;scanf("%d",&T); while(T--) { int n,m;scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&t[i][j]),p[i][j]=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) b[j].id=j,b[j].val=t[i][j],tmp[j]=0; sort(b+1,b+m+1,cmp1); for(int j=2;j<=m;j++) { if(b[j].val==b[j-1].val) tmp[b[j].id]=tmp[b[j-1].id]; else tmp[b[j].id]=j-1; } for(int j=1;j<=m;j++) p[i][j]+=tmp[j]; } for(int j=1;j<=m;j++) { for(int i=1;i<=n;i++) b[i].id=i,b[i].val=t[i][j],tmp[i]=0; sort(b+1,b+n+1,cmp2); for(int i=2;i<=n;i++) { if(b[i].val==b[i-1].val) tmp[b[i].id]=tmp[b[i-1].id]; else tmp[b[i].id]=i-1; } for(int i=1;i<=n;i++) p[i][j]+=tmp[i]; } int ans=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans=(ans+kp[p[i][j]])%mod; printf("%d\n",ans); } }
I.Course Selection System
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int T; int h[maxn], c[maxn]; int dp[maxn]; int main() { scanf("%d", &T); while(T --) { int N; long long ans = 0; scanf("%d", &N); long long sum1 = 0; for(int i = 0; i < N; i ++) { scanf("%d%d", &h[i], &c[i]); sum1 += c[i]; } for(int i=0;i<=sum1;i++) { dp[i]=0; } for(int i = 0; i < N; i ++) { for(int j = sum1; j >= c[i]; j --) { if(dp[j] < dp[j - c[i]] + h[i]) { dp[j] = dp[j - c[i]] + h[i]; long long cnt = 1LL*dp[j] * dp[j] - 1LL * dp[j] * j - 1LL * j * j; if(cnt > ans) ans = cnt; } } } printf("%lld\n", ans); } return 0; }
J.Knuth-Morris-Pratt Algorithm
#include <bits/stdc++.h> using namespace std; char t[1004]; int main() { int T;scanf("%d",&T); while(T--) { scanf("%s",t+1); int ans=0,len=strlen(t+1); for(int i=1;i<=len;i++) { if(t[i]==‘c‘&&i<=len-2&&t[i+1]==‘a‘&&t[i+2]==‘t‘) ans++; if(t[i]==‘d‘&&i<=len-2&&t[i+1]==‘o‘&&t[i+2]==‘g‘) ans++; } printf("%d\n",ans); } }
有队友的快落
FH
原文地址:https://www.cnblogs.com/zlrrrr/p/10467266.html
时间: 2024-11-12 17:55:21