2014/5/25 多校
生活随笔
收集整理的這篇文章主要介紹了
2014/5/25 多校
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
A:
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<set> 5 #define maxn 5+8*300000 6 using namespace std; 7 8 set<int>S; 9 int Enum=0,score[maxn],son[maxn][26],l[maxn]; 10 bool flag[maxn];//標(biāo)記是否打星 11 int tot_score,num,str_len;//個(gè)數(shù) 12 char ans_string[15]; 13 char Map[5][5]; 14 bool vis[5][5]; 15 void init(){ 16 tot_score=0;num=0;str_len=0; 17 } 18 int newnode(){ 19 Enum++; 20 memset(son[Enum],0,26*sizeof(son[Enum][0])); 21 flag[Enum]=false; 22 score[Enum]=0; 23 l[Enum]=0; 24 return Enum; 25 } 26 int cal_score(int len){ 27 if (len<=2) return 0; 28 if (len<=4) return 1; 29 if (len==5) return 2; 30 if (len==6) return 3; 31 if (len==7) return 5; 32 if (len==8) return 11; 33 } 34 void Insert(char *str){ 35 int u=0,len=strlen(str); 36 for(int i=0;i<len;i++){ 37 int id=str[i]-'A'; 38 if (son[u][id]==0){ 39 son[u][id]=newnode(); 40 } 41 u=son[u][id]; 42 } 43 //u是最底層,也代表當(dāng)前結(jié)點(diǎn) 44 score[u]=cal_score(len); 45 flag[u]=true; 46 l[u]=len; 47 } 48 int a[][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; 49 char ss[20]; 50 void dfs(int id,int x,int y,int k){ 51 52 if (flag[id] && S.count(id)==0){ 53 num++; 54 S.insert(id); 55 tot_score+=score[id]; 56 ss[k]='\0'; 57 if (l[id]>str_len || (l[id]==str_len && strcmp(ss,ans_string)<0)){ 58 str_len=l[id]; 59 strcpy(ans_string,ss); 60 } 61 } 62 for(int i=0;i<8;i++){ 63 int xx=x+a[i][0]; 64 int yy=y+a[i][1]; 65 if (xx<0 || yy<0 || xx>=4 || yy>=4) continue; 66 int v=Map[xx][yy]-'A'; 67 if(son[id][v] && !vis[xx][yy]) { 68 vis[xx][yy]=true; 69 ss[k]=Map[xx][yy]; 70 dfs(son[id][v],xx,yy,k+1); 71 vis[xx][yy]=false; 72 } 73 } 74 } 75 void solve(){ 76 for(int i=0;i<4;i++){ 77 for(int j=0;j<4;j++){ 78 int id=Map[i][j]-'A'; 79 if (son[0][id]>0){ 80 vis[i][j]=true; 81 ss[0]=Map[i][j]; 82 dfs(son[0][id],i,j,1); 83 vis[i][j]=false; 84 } 85 } 86 } 87 printf("%d %s %d\n",tot_score,ans_string,num); 88 } 89 int main(){ 90 memset(son[0],0,sizeof(son[0])); 91 int n; 92 scanf("%d",&n); 93 for(int i=0;i<n;i++){ 94 char s[20]; 95 scanf("%s",s); 96 Insert(s); 97 } 98 99 int m; 100 scanf("%d",&m); 101 102 for(int cas=1;cas<=m;cas++){ 103 S.clear();init(); 104 memset(vis,0,sizeof(vis)); 105 for(int i=0;i<4;i++) scanf("%s",Map[i]); 106 solve(); 107 } 108 return 0; 109 } View CodeB:
1 #include<iostream> 2 #include<string.h> 3 #include<stdio.h> 4 #include<math.h> 5 #include<queue> 6 #include<algorithm> 7 #include<vector> 8 #define maxn 11000 9 using namespace std; 10 11 struct Node{ 12 int s; 13 int type;//L點(diǎn)或者R點(diǎn); 14 bool operator<(const Node &X)const{ 15 if (X.s==s) return type>X.type; 16 return s<X.s; 17 } 18 }node[maxn]; 19 int N,C,cnt; 20 int y,m,d,h,s; 21 char day[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 22 int cal_time(){ 23 int ans=0; 24 ans+=(y-2013)*365*24*60; 25 for(int i=1;i<=12;i++){ 26 if (i<m){ 27 if (i==2){ 28 if (y==2016) ans+=29*24*60;else ans+=28*24*60; 29 }else { 30 ans+=day[i]*24*60; 31 } 32 }else break; 33 } 34 ans+=(d-1)*24*60; 35 ans+=h*60+s; 36 return ans; 37 } 38 void read(){ 39 char s1[50]; 40 scanf("%s",s1); 41 scanf("%d-%d-%d",&y,&m,&d); 42 scanf("%d:%d",&h,&s); 43 int t1=cal_time(); 44 node[cnt++]=(Node){t1,1}; 45 scanf("%d-%d-%d",&y,&m,&d); 46 scanf("%d:%d",&h,&s); 47 int t2=cal_time()+C; 48 node[cnt++]=(Node){t2,2}; 49 } 50 int solve(){ 51 int coun=0,ans=0; 52 sort(node,node+cnt); 53 for(int i=0;i<cnt;i++){ 54 if (node[i].type==1) ans=max(ans,++coun); 55 else coun--; 56 } 57 return ans; 58 } 59 int main(){ 60 // freopen("input.txt","r",stdin); 61 int T; 62 scanf("%d",&T); 63 while(T--){ 64 scanf("%d%d",&N,&C); 65 cnt=0; 66 for(int i=0;i<N;i++){ 67 read(); 68 } 69 printf("%d\n",solve()); 70 } 71 return 0; 72 } View CodeC:
1 #include<iostream> 2 #include<string.h> 3 #include<stdio.h> 4 5 using namespace std; 6 int x1,y1,x2,y2; 7 char c1,c2; 8 int a[][2]={{1,-1},{1,1},{-1,1},{-1,-1}}; 9 void read(){ 10 char s[5]; 11 scanf("%s",s); 12 c1=s[0]; 13 x1=8-(c1-'A'); 14 scanf("%s",s); 15 y1=s[0]-'0'; 16 scanf("%s",s); 17 c2=s[0]; 18 x2=8-(c2-'A'); 19 scanf("%s",s); 20 y2=s[0]-'0'; 21 return ; 22 } 23 bool same(){ 24 if (x1==x2 && y1==y2) return true;else return false; 25 } 26 void solve(){ 27 bool ans=false; 28 for(int i=0;i<4;i++){ 29 for(int j=1;j<=8;j++){ 30 int x=x1+a[i][0]*j; 31 int y=y1+a[i][1]*j; 32 if (!(x<=8 && x>=1 && y<=8 && y>=1)) break; 33 if ((x1-x)*(x-x2)+(y1-y)*(y-y2)==0) { 34 ans=true; 35 printf("2 %c %d %c %d %c %d\n",c1,y1,'A'+8-x,y,c2,y2); 36 break; 37 } 38 } 39 if (ans) break; 40 } 41 return ; 42 } 43 int main(){ 44 int T; 45 scanf("%d\n",&T); 46 while(T--){ 47 read(); 48 if ((x1+y1) % 2 != (x2+y2) % 2 ) { 49 printf("Impossible\n"); 50 continue; 51 } 52 if (same()){ 53 printf("%d %c %d\n",0,c1,y1); 54 continue; 55 } 56 int d1=x1-x2,d2=y1-y2; 57 if (d1==d2){ 58 printf("%d %c %d %c %d\n",1,c1,y1,c2,y2); 59 }else solve(); 60 } 61 return 0; 62 } View CodeD:
1 #include<iostream> 2 #include<string.h> 3 #include<stdio.h> 4 #include<math.h> 5 #include<queue> 6 #include<algorithm> 7 #include<vector> 8 using namespace std; 9 10 vector<int> G[155]; 11 int N; 12 int x[155],y[155]; 13 bool vis[155]; 14 bool bfs(){//找到一條從0到N+1點(diǎn)的通路 15 memset(vis,0,sizeof(vis)); 16 vis[0]=0; 17 queue<int>Q; 18 Q.push(0); 19 while(!Q.empty()){ 20 int u=Q.front();Q.pop(); 21 int cnt=G[u].size(); 22 for(int i=0;i<cnt;i++){ 23 int v=G[u][i]; 24 if (vis[v]) continue; 25 vis[v]=true; 26 Q.push(v); 27 } 28 } 29 if (vis[N+1]) return true;else return false; 30 } 31 int main(){ 32 int t; 33 scanf("%d",&t); 34 while(t--){ 35 scanf("%d",&N); 36 for(int i=0;i<=N+1;i++) G[i].clear(); 37 for(int i=0;i<=N+1;i++){ 38 scanf("%d%d",&x[i],&y[i]); 39 } 40 for(int i=0;i<=N+1;i++){ 41 for(int j=0;j<=N+1;j++){ 42 if (i==j) continue; 43 if (abs(x[i]-x[j])+abs(y[i]-y[j])<=1000) { 44 G[i].push_back(j); 45 } 46 } 47 } 48 if (bfs()) printf("happy\n");else printf("sad\n"); 49 } 50 return 0; 51 } View CodeE:
1 #include <iostream> 2 #include <cstdio> 3 #include <math.h> 4 using namespace std; 5 6 double A,B,H; 7 double V; 8 int N; 9 double F(double x){ 10 double ans= A*exp(-x*x)+B*sqrt(x); 11 return ans*ans*M_PI; 12 } 13 double simpson(double a,double b){ 14 double c=a+(b-a)/2; 15 return (F(a)+4*F(c)+F(b))*(b-a)/6; 16 } 17 double asr(double a,double b,double eps,double AA,int deep){ 18 double c=a+(b-a)/2; 19 double L=simpson(a,c),R=simpson(c,b); 20 if (fabs(L+R-AA)<=15*eps && deep>=4) return L+R+(L+R-AA)/15.0; 21 return asr(a,c,eps/2,L,deep+1)+asr(c,b,eps/2,R,deep+1); 22 } 23 double asr(double a,double b,double eps){ 24 return asr(a,b,eps,simpson(a,b),0); 25 } 26 double getans(){ 27 return asr(0,H,1e-10); 28 } 29 int main(){ 30 while(~scanf("%lf%d",&V,&N)){ 31 int ansp; 32 double m=100000000; 33 for(int i=1;i<=N;i++){ 34 scanf("%lf%lf%lf",&A,&B,&H); 35 double ans=getans(); 36 double ab=fabs(V-ans); 37 if (ab<m){ 38 ansp=i-1; 39 m=ab; 40 } 41 } 42 cout<<ansp<<endl; 43 } 44 return 0; 45 } 46 47 /************************************************************** 48 Problem: 1461 49 User: csu_newday 50 Language: C++ 51 Result: Accepted 52 Time:20 ms 53 Memory:1496 kb 54 ****************************************************************/ View CodeF:
1 #include<iostream> 2 #include<string.h> 3 #include<stdio.h> 4 #include<math.h> 5 #include<queue> 6 #include<algorithm> 7 #include<vector> 8 #define maxn 11000 9 using namespace std; 10 11 int a[][2]={{1,0},{-1,0},{0,1},{0,-1}}; 12 char Map[6][12]; 13 int ans,num;//答案,原來(lái)跳棋數(shù) 14 void read(){ 15 num=0; 16 for(int i=0;i<5;i++){ 17 scanf("%s",Map[i]); 18 int len=strlen(Map[i]); 19 for(int j=0;j<len;j++) 20 if (Map[i][j]=='o') num++; 21 } 22 return; 23 } 24 void dfs(){ 25 // for(int i=0;i<5;i++){ 26 // for(int j=0;j<9;j++) cout<<Map[i][j]; 27 // cout<<endl; 28 // } 29 bool still=false; 30 for(int x=0;x<5;x++){ 31 for(int y=0;y<9;y++){ 32 if (Map[x][y]=='o'){ 33 for(int i=0;i<4;i++){ 34 int x1=x+a[i][0]; 35 int y1=y+a[i][1]; 36 int x2=x+2*a[i][0]; 37 int y2=y+2*a[i][1]; 38 if (x1<0 || y1<0 || x1>=5 || y1>=9) continue; 39 if (x2<0 || y2<0 || x2>=5 || y2>=9) continue; 40 if (Map[x1][y1]=='o' && Map[x2][y2]=='.'){ 41 still=true; 42 Map[x1][y1]='.';Map[x2][y2]='o';Map[x][y]='.'; 43 dfs(); 44 Map[x1][y1]='o';Map[x2][y2]='.';Map[x][y]='o'; 45 } 46 } 47 } 48 } 49 } 50 if (!still){ 51 int coun=0; 52 for(int i=0;i<5;i++){ 53 for(int j=0;j<9;j++){ 54 if(Map[i][j]=='o') coun++; 55 } 56 } 57 ans=min(ans,coun); 58 } 59 return ; 60 } 61 void solve(){ 62 ans=10000; 63 dfs(); 64 } 65 int main(){ 66 // freopen("input.txt","r",stdin); 67 int t; 68 scanf("%d",&t); 69 while(t--){ 70 read(); 71 solve(); 72 printf("%d %d\n",ans,num-ans);//每次必然消去一個(gè),所以有直接關(guān)聯(lián)關(guān)系 73 } 74 return 0; 75 } View CodeG
H
I
J
K:
1 #include <iostream> 2 #include <math.h> 3 #include <string.h> 4 #include <stdio.h> 5 #define eps 1e-7 6 using namespace std; 7 int dcmp(double x){ 8 if (fabs(x)<eps) return 0; 9 if (x>eps) return 1; 10 else return -1; 11 } 12 struct Point3{ 13 double x,y,z; 14 }; 15 typedef Point3 Vector3; 16 Vector3 operator-(Vector3 A,Vector3 B){ 17 return (Vector3){A.x-B.x,A.y-B.y,A.z-B.z}; 18 } 19 Vector3 operator+(Vector3 A,Vector3 B){ 20 return (Vector3){A.x+B.x,A.y+B.y,A.z+B.z}; 21 } 22 Vector3 operator*(Vector3 A,double p){ 23 return (Vector3){A.x*p,A.y*p,A.z*p}; 24 } 25 double Dot(Vector3 A,Vector3 B){ 26 return A.x*B.x+A.y*B.y+A.z*B.z; 27 } 28 double Length(Vector3 A){ 29 return sqrt(Dot(A,A)); 30 } 31 Vector3 Cross(Vector3 A,Vector3 B){ 32 return (Vector3){A.y*B.z-A.z*B.y,A.z*B.x-A.x*B.z,A.x*B.y-A.y*B.x}; 33 } 34 double Area2(Point3 A,Point3 B,Point3 C){ 35 return Length(Cross(B-A,C-A)); 36 } 37 bool PointInTri(Point3 P,Point3 P0,Point3 P1,Point3 P2){ 38 double a1=Area2(P,P0,P1); 39 double a2=Area2(P,P1,P2); 40 double a3=Area2(P,P2,P0); 41 if (dcmp(a1)==0 || dcmp(a2)==0 || dcmp(a3)==0) return false; 42 return dcmp(a1+a2+a3-Area2(P0,P1,P2))==0; 43 } 44 bool TriSegInter(Point3 P0,Point3 P1,Point3 P2,Point3 A,Point3 B){ 45 Vector3 n=Cross(P1-P0,P2-P0); 46 if (dcmp(Dot(n,B-A))==0) return false; 47 else { 48 double t=Dot(n,P0-A)/Dot(n,B-A); 49 if (dcmp(t)<0 || dcmp(t-1)>0) return false; 50 Point3 P=A+(B-A)*t; 51 return PointInTri(P,P0,P1,P2); 52 } 53 } 54 Point3 p[10]; 55 int T; 56 int main(){ 57 while(cin>>T){ 58 for(int cas=1;cas<=T;cas++){ 59 bool ans=false; 60 for(int i=1;i<=6;i++){ 61 scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z); 62 } 63 int t1=0,t2=0; 64 if (TriSegInter(p[4],p[5],p[6],p[1],p[2])) t1++; 65 if (TriSegInter(p[4],p[5],p[6],p[1],p[3])) t1++; 66 if (TriSegInter(p[4],p[5],p[6],p[2],p[3])) t1++; 67 if (TriSegInter(p[1],p[2],p[3],p[4],p[5])) t2++; 68 if (TriSegInter(p[1],p[2],p[3],p[5],p[6])) t2++; 69 if (TriSegInter(p[1],p[2],p[3],p[4],p[6])) t2++; 70 if (t1==1 || t2==1) ans=true; 71 if (ans) printf("YES\n");else printf("NO\n"); 72 } 73 } 74 return 0; 75 } 76 77 /************************************************************** 78 Problem: 1467 79 User: csu_newday 80 Language: C++ 81 Result: Accepted 82 Time:8 ms 83 Memory:1500 kb 84 ****************************************************************/ View Code?比賽總結(jié):
1 2014/5/25 多校比賽總結(jié) 2 Little_W 3 綜述:這次比賽較簡(jiǎn)單,算法覆蓋面較大,平均每道題的難度不大。前期出題較穩(wěn)定,沒(méi)什么卡題的,電腦基本也沒(méi)歇著。這說(shuō)明什么呢?我們的水平還是比較擅長(zhǎng)中等的題。 4 5 A:字典樹(shù)維護(hù)+圖上dfs搜索。很容易想到暴力的方法,但是稍微算一下復(fù)雜度,就知道不可行。所以就想到要用數(shù)據(jù)結(jié)構(gòu)優(yōu)化查找搜索范圍的復(fù)雜度。編碼較復(fù)雜,容易寫(xiě)錯(cuò)。比賽時(shí)我估計(jì)編碼會(huì)出錯(cuò),所以讓隊(duì)友來(lái)敲了。 6 7 B:年份數(shù)據(jù)預(yù)處理+掃描出時(shí)間點(diǎn)穿過(guò)的最大區(qū)間(大白書(shū)上原有模型)當(dāng)時(shí)注意了一下是2012--2016保證預(yù)處理成分鐘一定不超long long就沒(méi)什么問(wèn)題了。掃描部分只有O(nlgn+n)不是很高。因?yàn)闀r(shí)間預(yù)處理容易出錯(cuò),隊(duì)友接手了這個(gè)題。當(dāng)時(shí)這樣安排是對(duì)的,讓我有時(shí)間去思考別的題目。 8 9 C:找到必然策略(機(jī)智題)。首先黑白染色的棋盤(pán)讓我想到了一個(gè)有趣的游戲(證明能否對(duì)角線(xiàn)移動(dòng)到),這個(gè)是奇偶剪枝的特例了。之后證明最多兩步,必然能移動(dòng)。沿對(duì)角線(xiàn)移動(dòng)的過(guò)程,暴力枚舉即可。 10 11 D:預(yù)處理無(wú)向圖+找面點(diǎn)間通路存在性。用簡(jiǎn)單證明可知1000以?xún)?nèi)距離即可連邊。找通路存在性,可以BFS不斷擴(kuò)展邊。去年寫(xiě)這個(gè)的時(shí)候,用的是Floyd的性質(zhì):就是一遍Floyd后就能判任意點(diǎn)對(duì)間的聯(lián)通與否,把邊表示成bool即可。但是后者較暴力。 12 13 E:簡(jiǎn)單的積分運(yùn)算題,運(yùn)用微分的思想,變換一下公式即可。要是求繞y軸旋轉(zhuǎn),求反函數(shù)再積分即可。 14 15 F:跳棋。暴力搜索題?我手動(dòng)算計(jì)復(fù)雜度上限,覺(jué)得暴力不可做。幸好隊(duì)友試了一下,DFS記錄最大值,A了。不過(guò)后來(lái)想想,好像很難再對(duì)算法優(yōu)化了。后來(lái)寫(xiě)了個(gè)更暴力的,都A了,更加不怎么明白為什么不會(huì)超時(shí)? 16 17 G:貪心(wait) 18 19 H:wait 題還沒(méi)看懂 20 21 I:。。。 22 23 J:待補(bǔ)充 24 25 K:三維幾何+暴力枚舉所有情況(判斷每條邊是否穿過(guò)一個(gè)三角形的面)。當(dāng)時(shí)題目沒(méi)看明白,看數(shù)據(jù)猜測(cè)的。判斷線(xiàn)面交大白書(shū)上有模板。注意,兩條線(xiàn)穿過(guò),說(shuō)明是沒(méi)有套上的,三條線(xiàn)穿過(guò)是不可能的。事后想到如果判斷一條直線(xiàn)和空間中凸多邊形相交怎么做?答案是把凸多邊形按照邊的順序分成N-2個(gè)小三角形,枚舉判斷即可,記住和某一小三角行相交是也可能在面內(nèi)(比如和切割邊相交),簡(jiǎn)單想了一下, 即使凸多邊形是異面的,這個(gè)方法也是正確的。 View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/little-w/p/3751165.html
總結(jié)
以上是生活随笔為你收集整理的2014/5/25 多校的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基于HFSS的圆极化阵列天线设计
- 下一篇: django源码简析——后台程序入口