Problem A. Cube IV
#include <iostream> using namespace std; int loc[1000001][2]; int main(){ int T,S; //scanf("%d",&T); freopen("/Users/lyd/Downloads/A-large.in", "r", stdin); scanf("%d",&T); for (int k=1; k<=T; k++) { scanf("%d",&S); for (int i=0; i<S; i++) { for (int j=0; j<S; j++) { int map; scanf("%d",&map); loc[map][0]=i; loc[map][1]=j; } } int res=-1,step=-1; int prex=-100,prey=-100; int tempres=0; // int MAXS=1<<31; // printf("%d",MAXS); for (int i=S*S; i>=1; i--) { int x=loc[i][0]; int y=loc[i][1]; if (abs(x-prex)+abs(y-prey)==1) {//up,down,left,right tempres++; }else{ tempres=1; } if (tempres>=step) { step=tempres;//steps res=i;//start point } prex=x; prey=y; } printf("Case #%d: %d %d\n",k,res,step); } return 0; }
Problem B. GBus count
#include <cstdio> #include <iostream> using namespace std; int main(){ int T,N; freopen("/Users/lyd/Downloads/B-large.in", "r", stdin); scanf("%d",&T); for (int k=0; k<T ; k++) { scanf("%d",&N); int **p; p=new int *[N]; for (int i=0; i<N; i++) { p[i]=new int[2]; } for (int i=0; i<N; i++) { scanf("%d %d",&p[i][0],&p[i][1]); } int cN; scanf("%d",&cN); int *q=new int[cN]; for (int i=0; i<cN; i++) { q[i]=0; } int ci; for (int i=0; i<cN; i++) { scanf("%d",&ci); for (int j=0; j<N; j++) { if (p[j][0]<=ci&&p[j][1]>=ci) { q[i]++; } } } printf("Case #%d:",k+1); for (int i=0; i<cN; i++) { printf(" %d",q[i]); } printf("\n"); } return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int findArr(string str,string s[],int N){ for (int i=0; i<N; i++) { if (str==s[i]) { return i; } } return -1; } int main(){ int T,N; freopen("/Users/lyd/Downloads/C-large.in", "r", stdin); scanf("%d",&T); for (int k=0; k<T ; k++) { scanf("%d",&N); string *l; string *r; l=new string [N]; r=new string [N]; for (int i=0; i<N; i++) { cin>>l[i]; cin>>r[i]; } string st; string ed; int si=0; // int ei=0; //find the start point for (int i=0; i<N; i++) { //cout<<l[i]<<" "<<r[i]<<endl; if (findArr(l[i], r,N)==-1) { st=l[i]; si=i; } } /* //find the end point for (int i=0; i<N; i++) { if (findArr(r[i], l,N)==-1) { ed=r[i]; ei=i; } }*/ cout<<"Case #"<<k+1<<":"; for (int i=0; i<N; i++) { int t=findArr(st, l,N); string ed=r[t]; cout<<" "<<st<<"-"<<ed; st=ed; si=t; } cout<<endl; //cout<<" "<<st<<"-"<<ed<<endl; } return 0; }