codeforces#321 (DIV2)
A question: water problem.
#include <bits/stdc++.h>#defineREP (I,A,B) for (int i=a;i<=b;i++)using namespaceStd;typedefLong Longll;Const intmaxn=1000100; ll N,A[MAXN];intMain () {//freopen ("In.txt", "R", stdin); while(cin>>N) {REP (i,1, N) scanf ("%i64d",&A[i]); intans=1, now=1; REP (i,2, N) { if(a[i]>=a[i-1]) now++; Elsenow=1; Ans=Max (Ans,now); } printf ("%d\n", ans); } return 0;}
View Code
Question B: sort + greedy, water problem.
#include <bits/stdc++.h>#defineREP (I,A,B) for (int i=a;i<=b;i++)using namespaceStd;typedefLong Longll;Const intmaxn=1000100;intn,d;structnode{ll M,s; FriendBOOL operator<(Node a,node B) {if(A.M<B.M)return 1; if(A.M==B.M)returna.s<B.S; return 0; }}; Node A[MAXN];intMain () {Freopen ("In.txt","R", stdin); while(cin>>n>>d) {REP (i,1, N) {scanf ("%i64d%i64d",&a[i].m,&a[i].s); } ll ans=0, now=0; Sort (a+1, a+n+1); intL=1, r=1; REP (R,1, N) { if(a[r].m-a[l].m<d) now+=A[r].s; Else{ Now+=A[r].s; while(A[r].m-a[l].m>=d) now-=a[l++].s; } //cout<<l<< "" <<r<< "" <<now<<endl;ans=Max (Ans,now); } cout<<ans<<Endl; } return 0;}
View Code
Question c: DFS, water problem.
#include <bits/stdc++.h>#defineREP (I,A,B) for (int i=a;i<=b;i++)#definePB push_back#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn=1000100;intn,m;intHas[maxn];vector<int>G[MAXN];intu,v;intDEG[MAXN];intDfsintPreintUintcat) { if(Has[u]) cat+=Has[u]; Elsecat=0; if(cat>m)return 0; if(u!=1&°[u]==1)return 1; intres=0; for(intI=0; I<g[u].size (); i++){ intv=G[u][i]; if(V==pre)Continue; Res+=DFS (U,V,CAT); } returnRes;}intMain () {//freopen ("In.txt", "R", stdin); while(cin>>n>>L) {REP (i,0, N) G[i].clear (); REP (i,1, N) scanf ("%d",&Has[i]); MS0 (deg); REP (i,1, N-1) {scanf ("%d%d",&u,&v); G[u]. PB (v); G[V]. PB (U); Deg[u]+ +;d eg[v]++; } printf ("%d\n", DFS (0,1,0)); } return 0;}
View Code
Question d: dp,tsp pressure.
When the game was written, the recursion didn't even!!!!!!!!!. After the game changed to the memory of the search direct 1 a .... It seems that the TSP will write a memory of the form of search more insurance.
#include <bits/stdc++.h>#defineREP (I,A,B) for (int i=a;i<=b;i++)#definePB push_back#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn=1100;Const intInf= (1<< in);intn,m,k;ll c[maxn][maxn];ll a[maxn];ll x,y,z;ll dp[ -][1<< -];ll cnt[1<< -];intCnt (intx) { intres=0; for(intI=0;(1<<i) <=x;i++){ if(x& (1<<i)) res++; } returnRes;}voidInit () { for(intI=0;i< (1<< -); i++) {Cnt[i]=Cnt (i); }}ll DFS (intIints) {ll&res=Dp[i][s]; if(~res)returnRes; if((s& (1<<i)) = =0)returnres=-INF; if(cnt[s]==1)returnres=A[i]; for(intj=0; j<n;j++){ if(I==J)Continue; if(s& (1<<J)) Res=max (Res,dfs (j,s^ (1<<i)) +c[j][i]+A[i]); } returnRes;}intMain () {Freopen ("In.txt","R", stdin); Init (); while(cin>>n>>m>>k) {REP (i,0, N-1) scanf ("%i64d",&A[i]); MS0 (c); while(k--) {scanf ("%i64d%i64d%i64d",&x,&y,&z); X--;y--; C[x][y]=Z; } memset (DP,-1,sizeof(DP)); ll ans=0; for(intI=0; i<n;i++){ for(ints=0;s< (1<<N); s++){ if(cnt[s]==m) ans=Max (Dfs (i,s), ans); }} printf ("%i64d\n", ans); } return 0;}
View Code
Although D test Instructions field did not, but still up points, if the D has gone straight up to purple, although did not rise to purple, but today in addition to the D TSP no outdated failed to change to the memory of the search form this bad, other game strategy hand speed basically no problem. Feel that they are closer to the purple name, but still want to learn more algorithms and data structures, ac automata, suffix automata, splay,lct, game theory, mathematics, number theory, computational geometry, graph theory, various DP, and so on, there is a lot to learn.
Yes, there is the e-question, line tree, fill and fill!!!
Codeforces round #321 (DIV2)