标签:return puts travel china can escape asi connect out
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2084 Accepted Submission(s): 1348
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 1e6+5; const int INF=0x3f3f3f3f; int main() { ll n,k; while(cin>>n>>k) { cout<<k*(n-k+1)<<endl; } return 0; }
#include<iostream> #include<algorithm> #include<stdio.h> using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; int a[N],g[N],f[N],b[N],c[N],n,h[N]; int main() { int t,n,last,l,i,m,x; cin>>t; while(t--) { cin>>n>>m; for(int i=0; i<n; i++) cin>>a[i],h[n-i-1]=a[i]; fill(g,g+n,INF); b[0]=1; for(int i=0; i<n; i++) { int j=lower_bound(g, g+n,a[i])-g; g[j]=a[i]; b[i]=j; } l=lower_bound(g, g+n,INF)-g-1; last=INF; for(i=n-1;i>=0;i--) { if(l==-1)break; if(b[i]==l&&a[i]<last) { last=a[i]; c[l]=last; l--; } } l=lower_bound(g, g+n,INF)-g; l=n-l;x=l; fill(g,g+n,INF); b[0]=1; for(int i=0; i<n; i++) { int j=lower_bound(g, g+n,h[i])-g; g[j]=h[i]; b[i]=j; } l=lower_bound(g, g+n,INF)-g-1; last=INF; for(i=n-1;i>=0;i--) { if(l==-1)break; if(b[i]==l&&a[i]<last) { last=a[i]; c[l]=last; l--; } } l=lower_bound(g, g+n,INF)-g; if(x>n-l) x=n-l; if(x<=m) puts("A is a magic array."); else puts("A is not a magic array."); //printf("%d\n",l); } return 0; }
找规律+矩阵快速幂
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; const long long M =998244353; struct Matrix { long long a[2][2]; Matrix() { memset(a, 0, sizeof(a)); } Matrix operator * (const Matrix y) { Matrix ans; for(long long i = 0; i <= 1; i++) for(long long j = 0; j <= 1; j++) for(long long k = 0; k <= 1; k++) ans.a[i][j] += a[i][k]*y.a[k][j]; for(long long i = 0; i <= 1; i++) for(long long j = 0; j <= 1; j++) ans.a[i][j] %= M; return ans; } void operator = (const Matrix b) { for(long long i = 0; i <= 1; i++) for(long long j = 0; j <= 1; j++) a[i][j] = b.a[i][j]; } }; long long solve(long long x) { Matrix ans, trs; ans.a[0][0] = ans.a[1][1] = 1; trs.a[0][0] = trs.a[1][0] = trs.a[0][1] = 1; while(x) { if(x&1) ans = ans*trs; trs = trs*trs; x >>= 1; } return ans.a[0][0]; } int main() { long long n; while(~scanf("%lld", &n)) { cout <<(solve(2*n+2)-1+M)%M << endl; } return 0; }
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 2245 Accepted Submission(s): 682
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; vector<pair<int,int> >G[N]; int sell[N],buy[N],ans; int vis[N]; void dfs(int x) { for(int i=0;i<(int)G[x].size();i++) { int v=G[x][i].first; int w=G[x][i].second; if(vis[v])continue; vis[v]=1; dfs(v); buy[x]=min(buy[x],buy[v]+w); sell[x]=max(sell[x],sell[v]-w); } ans=max(ans,buy[x]-sell[x]); ans=max(ans,sell[x]-buy[x]); } int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) G[i].clear(); for(int i=1;i<=n;i++) { scanf("%d",&sell[i]); buy[i]=sell[i]; } for(int i=1;i<n;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); G[u].push_back({v,w}); G[v].push_back({u,w}); } ans=0; vis[1]=1; dfs(1); printf("%d\n",ans); } return 0; }
For the sample input: + If WYJ doesn‘t move the cards pile, when the game starts the state of cards is: 4 6 2 8 4 1 5 7 9 2 WYJ can take the first three piles of cards, and during the process, the number of face-up cards is 4-1+6-5+2-7. Then he can‘t pay the the "penalty value" of the third pile, the game ends. WYJ will get 12 cards. + If WYJ move the first four piles of cards to the end, when the game starts the state of cards is: 4 4 6 2 8 2 1 5 7 9 WYJ can take all the five piles of cards, and during the process, the number of face-up cards is 4-2+4-1+6-5+2-7+8-9. Then he takes all cards, the game ends. WYJ will get 24 cards. It can be improved that the answer is 4. **huge input, please use fastIO.**
直接模拟下,但是有个细节就是全部都可以取到
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; int a[1000005],b[1000005]; int main() { int n,x,i,s,p,y,q,r; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d",&a[i]),b[i]=a[i]; for(i=0;i<n;i++) { scanf("%d",&x); a[i]-=x; } s=0;p=i;y=0;q=0;r=0; for(i=0;i<n;i++) { s+=a[i]; if(s<0) { if(q<y) { q=y,r=p; } y=0; s=0; p=i+1; } y+=b[i]; } if(p==n) { printf("%d\n",r); continue; } for(i=0;i<p;i++) { s+=a[i]; if(s<0) { if(q<y) { q=y,r=p; } break; } y+=b[i]; } if(q<y) { q=y,r=p; } printf("%d\n",r); } }
2017 ACM/ICPC Asia Regional Shenyang Online
标签:return puts travel china can escape asi connect out
原文地址:http://www.cnblogs.com/BobHuang/p/7517955.html