链接:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=599
A、
pog loves szh I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 393 Accepted Submission(s): 271
However, szh thinks it is boring, so he reverses the second string, like changing "efgh" to "hgfe". Then mix them as usual, resulting in "ahbgcfde".
Now, here comes a problem. Pog is given a string after mixing by szh, but he wants to find the original two strings.
Hint : In this question, it needs a linefeed at the end of line at hack time.
Then follows T lines. Every lines has a string S, whose length is even and not more than 100, and only consists of lower-case characters('a'~'z').
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <string> #include <map> using namespace std; #define ll long long #define INF 0x3f3f3f3f #define N 2010 int len; char s[N]; string s1,s2; int main() { int T; scanf("%d",&T); while(T--) { s1=s2=""; scanf("%s",s+1); len=strlen(s+1); for(int i=1;i<=len;i+=2) { s1+=s[i]; s2+=s[i+1]; } reverse(s2.begin(),s2.end()); cout<<s1<<endl<<s2<<endl; } return 0; }
B、
pog loves szh II
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1737 Accepted Submission(s): 509
For each case:
The following line contains two integers,n(2≤n≤100000),p(1≤p≤231−1)。
The following line contains n integers ai(0≤ai≤231−1)。
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <string> #include <map> using namespace std; #define ll long long #define INF 0x3f3f3f3f #define N 100010 int n,p; int a[N]; template <class T> inline bool input(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } int main() { while(input(n)) { input(p); for(int i=1;i<=n;i++) { input(a[i]); if(a[i]>=p) a[i]%=p; } sort(a+1,a+n+1); int ans=-1; for(int i=1;i<=n;i++) { int UP=p-1-a[i]; int x=upper_bound(a+1,a+n+1,UP)-a; if(x-1>i) ans=max(ans,a[i]+a[x-1]); if(i!=n) ans=max(ans,a[i]+a[n]-p); } printf("%d\n",ans); } return 0; }
C、
pog loves szh III
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 781 Accepted Submission(s): 164
Hint : You should be careful about stack overflow !
The following line contains ans integers,n(2≤n≤300000).
AT The following n−1 line, two integers are bi and ci at every line, it shows an edge connecting bi and ci.
The following line contains ans integers,Q(Q≤300000).
AT The following Q line contains two integers li and ri(1≤li≤ri≤n).
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") //防爆栈,也可以使用bfs代替dfs #define min(a,b) ((a)<(b)?(a):(b)) #define N 300010 #define M N*2 struct edge { int u,v,next; }edge[M]; int tot,head[N]; int n,m; int idx; bool vis[N]; int ver[2*N]; int dep[2*N]; int first[N]; int dp[2*N][20]; template <class T> inline bool input(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } void init() { tot=0; memset(head,-1,sizeof(head)); } void add(int u,int v) { edge[tot].u=u; edge[tot].v=v; edge[tot].next=head[u]; head[u]=tot++; } void init2() { idx=0; memset(vis,0,sizeof(vis)); } void dfs(int u,int d) { vis[u]=1; ver[++idx]=u; first[u]=idx; dep[idx]=d; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(!vis[v]){ dfs(v,d+1); ver[++idx]=u; dep[idx]=d; } } } void ST(int n) { int i,j; for(i=1;i<=n;i++) dp[i][0]=i; for(j=1;(1<<j)<=n;j++){ for(i=1;i<=n;i++){ if(i+(1<<j)-1<=n){ int a=dp[i][j-1]; int b=dp[i+(1<<(j-1))][j-1]; dp[i][j]=dep[a]<dep[b]?a:b; } } } } int RMQ(int i,int j) { int k=(int)(log((double)(j-i+1))/log(2.0)); int a=dp[i][k],b=dp[j-(1<<k)+1][k]; return dep[a]<dep[b]?a:b; } int LCA(int u,int v) { int x=first[u]; int y=first[v]; if(x>y) swap(x,y); int res=RMQ(x,y); return ver[res]; } int main() { while(input(n)) { init(); for(int i=1;i<n;i++) { int u,v,w; input(u); input(v); add(u,v); add(v,u); } init2(); dfs(1,0); ST(2*n-1); input(m); while(m--) { int u,v; input(u); input(v); printf("%d\n",LCA(u,v)); } } return 0; }
D、
pog loves szh IV
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 78 Accepted Submission(s): 13
Pog and Szh choose two different nodes on the tree, then pog walks to szh along the paths of the tree and records the weight. Because of too many nodes, pog only records the XOR of all weight of the nodes he passes for convenient.Due to szh's love for pog,szh wanders the sum of which pog records for any n∗(n−1)different combinations.
Because of tired of szh's corny pursuit, pog changes aA into B at every moment, of course, szh must output the answer of all moment.
In every group, two integers at first line are n(2≤n≤10000) and Q(1≤Q≤10000).
At the following line, n integers are ai(0≤ai<32768).
At the following n−1 line, two integers are bi and ci at every line, it shows an edge connecting bi and ci.
At the following Q line, two integers are A(1≤A≤n) and B(0≤B<32768) at every line, it shows that changing aA into B.