ACM-ICPC协会程序设计大赛解题报告
ACM解题报告

问题重述:给出n种邮票,每种邮票有自己的面值(面值可能重复)指定m种“总面值”,对每种“总面值”,求解满足如下条件的组合以达到该“总面值”(1)所用邮票在n种中可以重复选取(2)所用邮票张数〈=4(3)尽量多的适应那个不同总类的邮票Max (Stamp Types)(4)若有多种方案满足(3),则选取张数最小的一种方案Min (Stamp Num)(5)若有多种方案满足(3)(4),则选取“最大面额”最高的一种方案。
Max(Heightest Value) (6)若有多种方案满足(3)(4)(5)则输出“tie”题目分析:(1)算法定位:从题目的条件可知,此题必须遍求所有方案以求解,因此采用搜索的方法是非常合理的,因为题目带由一定的递推性,也可以尝试动态规划的方法.(2)问题优化与简化对于搜索型题目,关键的优化就是减少重复计算,本题可由3方面的简化,避免重复性计算.(1)对于面额相等的邮票,可以限制在1~5张,多余的可以不处理,例如这样的输入:1 1 1 1 1 1 1 1 0 8个14 0可以简化成为:1 1 1 1 1 0 5个14 0他们的解是相同的(2)搜索求解时约定, 后一张邮票面额>=前面张邮票的面额,即如下的6种情况:1 2 3 2 3 1 3 12 1 3 2 3 2 1 2 1 3只需搜索判断一种,即 1 2 3 的情况(3)对于给定的n种邮票,遍历4张邮票的所有可达“总面额”的解,当m种指定面额给出,只需插标输出即可,不需要重复m次类似的搜索。
(因为m次的搜索中,很多是重复计算的)(3)算法介绍(1)搜索方法一:(base on 史诗’s program)主要思路:4重循环,枚举所有可能,依据题目条件保留最优解。
For(i=1;i<=total_stamps;i++)For(j=i;j<=total_stamps;j++)For(k=j;k<=total_stamps;k++)For(l=k;l<=total_stamps;l++){更新最优解}优化:使用优化方案(1)(2),修改后可以加上优化方案(3)评价:编程复杂度低,代码少,运行时空效率高,比赛时候推荐使用但是扩展性受限制,若题目给的是任一k张而不是4,则必须大量修改代码(2)搜索方法二:(base on hawking’s program)主要思路:递归深度搜索,遍历所有k张邮票的可达面额的解,保留每种面额的最优解,查表输出指定面额的解,并给定k=4,即为题目要求的情况。
ACM解题报告

题目一:DescriptionSome positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive primenumbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.Your mission is to write a program that reports the number of representations for the given positive integer.InputThe input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. OutputThe output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.Sample Input231741206661253Sample Output1123121.算法通过筛法找出10000以内所有的素数,存到数组里。
2018ACM-ICPC南京区域赛题解

2018ACM-ICPC南京区域赛题解解题过程开场开A,A题shl看错题意,被制⽌。
然后开始⼿推A,此时byf看错E题题意,开始上机。
推出A的规律后,shl看了E题,发现题意读错。
写完A题,忘记判断N=0的情况,WA+1。
过了A后,shl重新写E,lfw开始开J题,E题过不了样例,lfw多次起⽴让shl调试,然后shl拿到E的⼀⾎,lfw之后过了J。
byf开始开I题,shl⼝胡出M做法,然后lfw和shl⼀起推G题。
byf过了I题后,shl推出G题,byf去写。
然后lfw开始计算⼏何,经过查错后过掉,然后shl开始开M题,过掉后还剩最后半⼩时,⽆题可做。
最后罚时很多,因为前期签到题过得太慢,A题40+分钟才过,J题1⼩时40分钟才过。
题解A - Adrien and Austin题解:给你n给⽯头,下标依次为1~n,然后两个⼈轮流取⽯头,每次取1~k个连续下标的⽯头,最后不能取得输掉⽐赛。
问你谁会获胜。
找规律,⾸先,n==0时,第⼀个⼈必败。
k==1时,n为奇数时先⼿必胜。
k>1时,先⼿必胜.参考代码:1 #include<bits/stdc++.h>2using namespace std;3 typedef long long LL;4const int mod=1e9+7;5 LL quick_pow(LL a,LL b)6 {7 LL ans=1;8while(b)9 {10if(b&1) ans=ans*a%mod;11 a=a*a%mod;12 b>>=1;13 }14return ans;15 }16int main()17 {18int t;19 scanf("%d",&t);20int l24=quick_pow(24,mod-2);21while(t--)22 {23int n;24 scanf("%d",&n);25 LL ans=1;26 ans=ans*n%mod;27 ans=ans*(n+1)%mod;28 ans=ans*(n+2)%mod;29 ans=ans*(n+3)%mod;30 ans=ans*l24%mod;31 printf("%lld\n",ans);32 }33 }View CodeB - TournamentUnsolved.C - Cherry and ChocolateUnsolved.D - Country Meow队友写的.题解:https:///liufengwei1/article/details/89303612参考代码:1 #include<bits/stdc++.h>2#define maxl 1103#define eps 1e-84struct point5 {6double x,y,z;7 point(double a=0,double b=0,double c=0)9 x=a;y=b;z=c;10 }11 };1213int npoint,nouter;14 point pt[maxl],outer[4],res;15double radius,tmp,ans;1617 inline double dist(point p1,point p2)18 {19double dx=p1.x-p2.x,dy=p1.y-p2.y,dz=p1.z-p2.z; 20return (dx*dx+dy*dy+dz*dz);21 }2223 inline double dot(point p1,point p2)24 {25return p1.x*p2.x+p1.y*p2.y+p1.z*p2.z;26 }2728 inline void ball()29 {30 point q[3];double m[3][3],sol[3],L[3],det;31int i,j;32 res.x=res.y=res.z=radius=0;33switch(nouter)34 {35case1: res=outer[0];break;36case2:37 res.x=(outer[0].x+outer[1].x)/2;38 res.y=(outer[0].y+outer[1].y)/2;39 res.z=(outer[0].z+outer[1].z)/2;40 radius=dist(res,outer[0]);41break;42case3:43for(int i=0;i<2;i++)44 {45 q[i].x=outer[i+1].x-outer[0].x;46 q[i].y=outer[i+1].y-outer[0].y;47 q[i].z=outer[i+1].z-outer[0].z;48 }49for(int i=0;i<2;i++)50for(int j=0;j<2;j++)51 m[i][j]=dot(q[i],q[j])*2;52for(int i=0;i<2;i++)53 sol[i]=dot(q[i],q[i]);54if(fabs(det=m[0][0]*m[1][1]-m[0][1]*m[1][0])<eps) 55return;56 L[0]=(sol[0]*m[1][1]-sol[1]*m[0][1])/det;57 L[1]=(sol[1]*m[0][0]-sol[0]*m[1][0])/det;58 res.x=outer[0].x+q[0].x*L[0]+q[1].x*L[1];59 res.y=outer[0].y+q[0].y*L[0]+q[1].y*L[1];60 res.z=outer[0].z+q[0].z*L[0]+q[1].z*L[1];61 radius=dist(res,outer[0]);62break;63case4:64for(int i=0;i<3;i++)65 {66 q[i].x=outer[i+1].x-outer[0].x;67 q[i].y=outer[i+1].y-outer[0].y;68 q[i].z=outer[i+1].z-outer[0].z;69 sol[i]=dot(q[i],q[i]);70 }71for(int i=0;i<3;i++)72for(int j=0;j<3;j++)73 m[i][j]=dot(q[i],q[j])*2;74 det=m[0][0]*m[1][1]*m[2][2]75 + m[0][1]*m[1][2]*m[2][0]76 + m[0][2]*m[2][1]*m[1][0]77 - m[0][2]*m[1][1]*m[2][0]78 - m[0][1]*m[1][0]*m[2][2]79 - m[0][0]*m[1][2]*m[2][1];80if(fabs(det)<eps) return;81for(int j=0;j<3;j++)82 {83for(int i=0;i<3;i++)84 m[i][j]=sol[i];85 L[j]=(m[0][0]*m[1][1]*m[2][2]86 +m[0][1]*m[1][2]*m[2][0]87 +m[0][2]*m[2][1]*m[1][0]88 -m[0][2]*m[1][1]*m[2][0]89 -m[0][1]*m[1][0]*m[2][2]90 -m[0][0]*m[1][2]*m[2][1])/det;91for(int i=0;i<3;i++)92 m[i][j]=dot(q[i],q[j])*2;93 }94 res=outer[0];95for(int i=0;i<3;i++)96 {98 res.y+=q[i].y*L[i];99 res.z+=q[i].z*L[i];100 }101 radius=dist(res,outer[0]);102 }103 }104105 inline void minball(int n)106 {107 ball();108if(nouter<4)109for(int i=0;i<n;i++)110if(dist(res,pt[i])-radius>eps)111 {112 outer[nouter]=pt[i];113 ++nouter;114 minball(i);115 --nouter;116if(i>0)117 {118 point Tt=pt[i];119 memmove(&pt[1],&pt[0],sizeof(point)*i);120 pt[0]=Tt;121 }122 }123 }124125 inline double smallest_ball()126 {127 radius=-1;128for(int i=0;i<npoint;i++)129if(dist(res,pt[i])-radius>eps)130 {131 nouter=1;132 outer[0]=pt[i];133 minball(i);134 }135return sqrt(radius);136 }137138 inline void prework()139 {140for(int i=0;i<npoint;i++)141 scanf("%lf%lf%lf",&pt[i].x,&pt[i].y,&pt[i].z);142 }143144 inline void mainwork()145 {146 ans=smallest_ball();147 }148149 inline void print()150 {151 printf("%.5f\n",ans);152 }153154int main()155 {156while(~scanf("%d",&npoint))157 {158 prework();159 mainwork();160 print();161 }162return0;163 }View CodeE - Eva and Euro coins题解:给你两个01串,然后连续k个0可以翻转为1,连续k个1可以翻转为0.问你这两个01串是否可以变成相同的串。
解题报告

2011 ACM/ICPC亚洲区预选赛北京赛站解题报告Problem A. Qin Shi Huang’s National Road System难度:简单图论题。
题目大意:一个无向完全图,边有正权值,点也有正权值。
可以选择一条边,将其边权值变为0。
要求选定这条边(假定为e0)并将其权值变为0后,满足以下条件:A/B最大。
其中A是e0连接的两个点的点权值和,B是修改后的图的最小生成树的边权值和。
解题思路:先求一棵最小生成树,求的过程中,每加入一个点,就记录已经在树上的所有点到该点的路径(树上的路径)上的最长边的权值。
然后枚举权值要变成0的边uv,如果uv不是树边,则用它替换uv路径上的最大权值边,o(1)时间即得新最小生成树的边权值和;uv是树边,新最小生成树的边权值和即为原最小生成树的边权值和减去边uv的权值。
Problem B. Hou Yi’s secret难度:最简单的枚举题,但是有trick。
题目大意:给定一些点,每三点可以连一个三角形,求相似三角形个数。
解题思路:点数很少,枚举所有的三角形即可。
trick是要去掉重点,以及三点共线就不能构成三角形。
Problem C. Three Kingdom Chess难度:难的搜索题。
题目大意:本题题目大意是在一个不超过5X5的棋盘上,诸葛亮和周瑜两人在下棋。
告诉你棋子的走动方式和攻击方式,两人总是使用最佳策略。
每个棋子有步兵、骑兵和弓兵三种可能,每个兵种有不同的移动力和攻击范围。
你每次能移动一枚棋子,然后用这枚棋子攻击敌方的某部队。
比赛将强制在K回合后结束,或者某方所有棋子全部死掉了。
最后的得分为双方的兵力差。
解题思路:本题是一个比较容易看出来的搜索题。
每次搜索当前玩家的行动方式(即搜索使用那枚棋子,移动到哪个位置,攻击哪个敌军)。
搜索树采用经典的博弈搜索树即可。
当然本题虽然数据范围不大,但也挺容易超时的。
标程所做的优化有两处。
第一个优化就是经典的alpha-beta剪枝了,由于比赛会强制在K回合后结束,并且双方永远采用最佳策略,因此alpha-beta剪枝几乎可以完美的应用在此处。
2018ACM-ICPCWorldFinals部分题题解

2018ACM-ICPCWorldFinals部分题题解Problem C. Conquer the World &&loj6405 征服世界题⽬⼤意:给定⼀棵树,树有边权。
每个点上有a_i个⼠兵,且每个点最终需要b_i个⼠兵。
求最⼩代价。
n\leq2.5*10^5,a_i,b_i\leq1e9。
题解:显然,我们可以直接⽤这棵树跑费⽤流。
但n太⼤了。
所以我们只能模拟⼀下费⽤流的过程了。
⾸先,为了保证所有的b_i都能选满,我们先给每个b_i加⼀个-INF的权值。
考虑维护两个堆,分别记录a的信息和b的信息。
DFS这棵树,设当前节点为u。
将u的所有⼉⼦的堆全部合并,每个点的初始权值是dis_i和dis_i-INF,指的是i到1号节点的距离。
这个可以⽤左偏树或者stl⾥的pb_ds实现。
将⼦树信息上传完成后,开始尝试将它们两两配对。
配对终⽌的条件是两个堆顶元素匹配的权值\geq 0。
然后考虑如何像费⽤流那样进⾏反悔操作。
如果当前的⼀个匹配点和另外⼀个点匹配了,那么就要撤销之前的匹配。
列出两次匹配的关系式,我们就可以分别得出计算a,b反悔代价的算式。
因为⼀个点的a和b不会同时反悔,且\sum b_i也不⼤,所以做法是正确的。
具体的反悔实现可以看我的代码。
时间复杂度:O(nlogn)代码:#include<bits/stdc++.h>using namespace std;#define re register int#define F(x,y,z) for(re x=y;x<=z;x++)#define FOR(x,y,z) for(re x=y;x>=z;x--)typedef long long ll;#define I inline void#define IN inline int#define C(x,y) memset(x,y,sizeof(x))#define STS system("pause")template<class D>I read(D &res){res=0;register D g=1;register char ch=getchar();while(!isdigit(ch)){if(ch=='-')g=-1;ch=getchar();}while(isdigit(ch)){res=(res<<3)+(res<<1)+(ch^48);ch=getchar();}res*=g;}const ll INF=1e12+7;struct E{int to,nt,w;}e[505000];#define T e[k].toqueue<int>q;struct Dat{ll w,f;Dat(ll _w=0,ll _f=0){w=_w;f=_f;}friend bool operator < (Dat x,Dat y){return x.w>y.w;}}d[2000000];int now,cnt,ch[2000000][2],dis[2000000],root[303000],rt[303000];int n,m,X,Y,W,a[303000],b[303000],head[303000],tot,sum;ll dep[303000],ans;IN new_node(){re res;if(q.empty())return ++cnt;res=q.front();q.pop();ch[res][0]=ch[res][1]=dis[res]=d[res].w=d[res].f=0;return res;}I add(int x,int y,int w){e[++tot].to=y;e[tot].nt=head[x];head[x]=tot;e[tot].w=w;}IN merge(int x,int y){if(!x||!y)return x+y;if(d[x]<d[y])swap(x,y);ch[x][1]=merge(ch[x][1],y);if(dis[ch[x][0]]<dis[ch[x][1]])swap(ch[x][0],ch[x][1]);dis[x]=dis[ch[x][1]]+1;return x;}I D_1(int x,int fa,ll depth){dep[x]=depth;if(a[x])d[x]=Dat(dep[x],a[x]),root[x]=x,dis[x]=0;else root[x]=0;if(b[x])d[x+n]=Dat(dep[x]-INF,b[x]),rt[x]=x+n,dis[x+n]=0;else rt[x]=0;for(re k=head[x];k!=-1;k=e[k].nt){if(T==fa)continue;D_1(T,x,depth+e[k].w);root[x]=merge(root[x],root[T]);rt[x]=merge(rt[x],rt[T]);}while(root[x]&&rt[x]&&d[root[x]].w+d[rt[x]].w-2*dep[x]<0){ll vala=d[root[x]].w,valb=d[rt[x]].w,tmp=min(d[root[x]].f,d[rt[x]].f),nowa=d[root[x]].f-tmp,nowb=d[rt[x]].f-tmp;ans+=(vala+valb-2*dep[x])*tmp;q.emplace(root[x]);q.emplace(rt[x]);//cout<<"!"<<root[x]<<" "<<rt[x]<<" "<<tmp<<" "<<vala<<" "<<valb<<" "<<dep[x]<<" "<<nowa<<" "<<nowb<<endl;root[x]=merge(ch[root[x]][0],ch[root[x]][1]);rt[x]=merge(ch[rt[x]][0],ch[rt[x]][1]);if(tmp){now=new_node();d[now]=Dat(2*dep[x]-valb,tmp);dis[now]=0;root[x]=merge(root[x],now);now=new_node();d[now]=Dat(2*dep[x]-vala,tmp);dis[now]=0;rt[x]=merge(rt[x],now);}if(nowa)now=new_node(),d[now]=Dat(vala,nowa),dis[now]=0,root[x]=merge(root[x],now);if(nowb)now=new_node(),d[now]=Dat(valb,nowb),dis[now]=0,rt[x]=merge(rt[x],now);}}int main(){read(n);C(head,-1);tot=-1;cnt=n<<1;dis[0]=-1;F(i,1,n-1){read(X);read(Y);read(W);add(X,Y,W);add(Y,X,W);}F(i,1,n){read(a[i]),read(b[i]);re tmp=min(a[i],b[i]);a[i]-=tmp;b[i]-=tmp;sum+=b[i];}D_1(1,0,0);/*while(rt[1]){ll vala=d[root[1]].w,valb=d[rt[1]].w,tmp=min(d[root[1]].f,d[rt[1]].f),nowa=d[root[1]].f-tmp,nowb=d[rt[1]].f-tmp;ans+=(vala+valb-2*dep[1])*tmp;//cout<<"!"<<tmp<<endl;root[1]=merge(ch[root[1]][0],ch[root[1]][1]);rt[1]=merge(ch[rt[1]][0],ch[rt[1]][1]);if(nowa)++now,d[now]=Dat(vala,nowa),dis[now]=0,root[1]=merge(root[1],now);if(nowb)++now,d[now]=Dat(valb,nowb),dis[now]=0,rt[1]=merge(rt[1],now);//cout<<now<<endl;}*/printf("%lld",ans+(ll)INF*sum);return 0;}/*31 2 53 1 52 15 01 361 2 21 3 51 4 12 5 52 6 10 01 02 12 10 10 1*/Problem I. Triangles && loj6411题⽬⼤意:给出⼀张毒瘤的图,求其中包含的三⾓形个数。
world finals 2009 solution acm icpc 总决赛 题解

ACM ICPC World Finals2009Solution sketchesDisclaimer These are unofficial descriptions of possible ways to solve the problems of the ACM ICPC World Finals2009.Any error in this text is my error.Should youfind such an error,I would be happy to hear about it at austrin@kth.se.Also,note that these sketches are just that—sketches.They are not intended to give a complete solution,but rather to outline some approach that can be used to solve the problem.If some of the terminology or algorithms mentioned below are not familiar to you,your favorite search engine should be able to help.Finally,I want to stress that while I’m the one who has written this document,I do not take credit for the ideas behind these solutions—they come from many different people.In particular,thanks to Derek Kisman for catching some errors in an earlier version of this document.—Per AustrinProblem A:A Careful ApproachSince the number of planes is at most8,an optimal solution can be found by simply try-ing all8!=40320possible orders for the planes to land.When trying a specific ordering, the largest possible landing window can be computed by binary searching over the maxi-mum possible window and then greedily checking whether a certain window length can be achieved.Something which may be easy to miss in this problem is that it can be the case that the landing time of a plane should be a non-integral number of seconds.Problem B:My BadThis problem essentially consists of two parts:evaluating circuits andfindingflawed gates.Evaluating circuits can be done in a straight-forward way,once the somewhat tedious input format has been parsed.Tofind theflawed gate in the case that the circuit isflawed, one can simply check each gate for each possible error.If more than one possible explanation for theflaw is found,the error can not be completely determined.Problem C:The Return of CarlFirst,suppose that the sequence of faces that Carl visits on his path is given.In this case, the path length can be found by laying out the triangles in2-dimensional Cartesian space, connected in the sequence they are visited.The length of the path is then simply given by the length of the line segment from the starting point’s location in the starting face,to the destination point’s location in the destination face.One may object that this is only true provided that the line segment stays inside the laid out triangles,and that,when laid out in the plane,the triangles will not overlap.However,it turns out that,first of all,the triangles will not overlap,and second,if the line segment does not stay inside the triangles,there willin fact be a different way of laying out the triangles such that the line segment stays inside the triangles and becomes shorter.Now,we are not given the sequence of faces visited,but because the number of faces is so small,one can simply try all possible such sequences.There are a lot of messy implementation details involved in getting this right.For in-stance,one has to be able tofind the location of a point in a triangle given its azimuth and zenith angles,and when laying out the triangles in the plane one needs to keep track of whether a move from one face to another constitutes a“left”turn or a“right”turn.Problem D:Conduit PackingThere are several ways of solving this problem,ranging from complicated solutions whose correctness is easy to prove,to somewhat easier solutions whose correctness is more difficult to prove.A natural starting point is to binary search for the minimum possible radius r of the outer circle.To check whether radius r is achievable,one can do as follows:start by placing the outer circle,and then try to place the small circles inside it,one by one.When placing a new circle,one can assume without loss of generality that there exists a circle which should touch two of the already placed circles(or the outer circles in case this is the only one placed so far).When all circles have been placed,one can check that none of them intersect to see if the placement succeeded.Trying all possible ways of placing the circles(with only four inner circles,there are only a few hundred different such ways),one can determine whether radius r is possible.Problem E:Fare and BalancedThis problem may atfirst look like some sort of maxflow problem,but even if the large size of the graph does not scare you away from this approach,I am not aware of any way of modeling the problem this way.Consider instead the following approach.Let U(u,v)be true if every path from intersec-tion u to intersection v has a unique cost.If U(1,N)is true it is clear that no tolls need to be added,so assume from now on that U(1,N)is not true.Now,suppose there is some vertex v such that both U(1,v)and U(v,N)is false.In this case,no solution can possibly exist,since such a solution would have to incur a toll both on some road“before”v and on some road “after”v in order to ensure that all paths have unique costs.Let us then suppose that no such vertex v exists,i.e.,that either U(1,v)or U(v,N)is true for every v.In this case,a solution can be constructed as follows:Let us say that an edge (u,v,c)from u to v of cost c is pivotal if it has the property that U(1,u)is true but U(1,v)is false.Pivotal edges have the following nice properties:•The fact that U(1,1)is true but U(1,N)is false,together with the fact that if U(1,u)is false and there is an edge from u to v,then U(1,v)is also false implies that every route from1to N contains exactly one pivotal edge.•The fact that U(1,v)is false implies that U(v,N)is true.Let C(1,N)denote the maximum length of a path from1to N Now consider adding a toll of C(1,N)−C(1,u)−C(v,N)−c to every pivotal edge(u,v,c),if this number is positive(note that it can not be negative).By the two properties above,it is now easily shown that every route from1to N has at most one toll and a total cost of exactly C(1,N).To make an efficient solution out of this,note that the only quantities we actually need are those of the form U(1,v),U(v,N),C(1,v)and C(v,N),and all such values can be computed in linear time using dynamic programming.Problem F:Deer-Proof FenceLet usfirst consider the special case of using a single fence.To compute the fence length needed,one computes the convex hull of the set of trees.It is then not hard to see that the minimum total fence length will be the total length of the perimeter of the convex hull,plus the circumference of a circle of radius M.Tofinish the problem we now need tofind a good way of partioning the set of trees into disjoint parts,each of which will be surrounded by a single fence(the perimeter of which can be computed as described above).Because of the small number of trees,an optimal such partition can be computed in a brute-force manner.In order to make it fast enough,one may need to use dynamic programming to remember,for a given set S of trees,what the minimum fence length for S is.Problem G:House of CardsThe main challenge in this problem is to build a convenient representation of the current game state,for computing the scores of the players and the possible next moves.With this hurdle out of the way,the problem can be solved using a standard min-max search,along with alpha-beta pruning to make the search fast enough.Problem H:The Ministers’Major MessThe solution is based on realising that a minister can have at most one unsatisfied vote (or in the case of k=1or k=2,a minister must have all votes satisfied).This can be expressed by k·(k−1)implications(if the decision on vote i is opposite to the minister’s opinion,then the decision on vote j must be according to the minister’s opinion,for all i=j). Alternatively,it can be expressed as a2-CNF formula(for each pair of two votes,at least one must be satisfied).Either way,this gives an efficient way of determining whether a solution exists,as2-SAT is efficiently solvable.Tofind out all values which are uniquely determined,the easiest way is to compute the transitive closure of the implications mentioned above,and then apply all known values.A variable is known if it is included in a k=1or k=2vote,or if it is implied by its negation.Problem I:Struts and SpringsThefirst part of this problem is to determine the tree hierarchy of the windows.This is fairly easy:the parent of a window W1is the smallest window W2such that W1is contained in W2 (if such a window exists).The second,more tedious part,is to handle resize operations.The horizontal and vertical dimensions can be handled separately and in the same way.Suppose some window W hasits outer window’s width changed by∆s.Let L be the total current length of the horizontal springs that control W(there are between one and three such springs).Then,a spring of length l gets resized to length l =l·(1+∆s/L).If the device controlling the width of W is a spring,the windows inside W must now be updated since W changed width.If the device controlling the width is a strut,the windows inside W are unchanged,except that their absolute position with respect to the screen may have changed because W or one of its parents may moved.Problem J:Subway TimingThe problem is probably most easily solved by binary search for the answer.However, checking whether it is possible to achieve a certain answer X is a bit tricky.There are a few different ways of checking this,ranging from quite complicated dynamic programming solutions to the more elegant direct solution described below.An important parameter in the runtime of all these solutions is what the maximum value of X can be.It is a nice(but surprisingly difficult)exercise to prove that,no matter what the size of the tree is, X does not have to be larger than118(the significance of this number is of course that it is 59·2,and that59is the maximum possible rounding error on a single edge).Root the tree arbitrarily,and consider some vertex v of the tree.Let us say that an interval [a,b]is permissible for v if the edges in the subtree rooted at v can be rounded in such a way that:•Every path in the subtree has an error of at most X.•Every path in the subtree which ends in v has an error which lies in the interval[a,b]. Note that a permissible interval must have a≤0and b≥0.Furthermore,let us say that an interval[a,b]is redundant for v if there is some b <b such that[a,b ]is permissible.Now,checking whether it is possible to achieve a maximum error of X is equivalent to checking whether there exists some permissible error for the root of the tree.We will do this by computing the set of all non-redundant permissible intervals for each node v.Fix some node v,let c be its number of children,and for i between0and c,let T i denote the subtree rooted at v but including only thefirst i children of v.Suppose[a,b]is a non-redundant permissible interval for T i−1,and that[a ,b ]is a non-redundant permissible interval for the subtree rooted at the i’th child of v,and that the error for the edge from v to its i’th child can be chosen as e(there are always one or two possible values for e).Then if a+a +e and b+b +e both are of absolute value at most X,[min(a,a +e),max(b,b +e)]is a permissible interval for T i.All non-redundant permissible intervals for T i can be constructed this way, but also some redundant ones.In order to keep the list of intervals short(of order X rather than order X2),one should prune away the redundant ones.Problem K:Suffix-Replacement GrammarsLet L be the length of the starting and target strings,and consider a directed graph G= (V,E)on strings of length L,where there is an edge from a string x to a string y if x can be transformed to y using one of the suffix-replacement rules.The problem asks for the shortest path from S to T in this graph—however,the graph has52L vertices and hence finding a shortest path by a standard BFS is not feasible.What saves us is the fact that the graph in question has a very special structure.Consider a path from S to T.Some of the transformation rules used involve suffixes of length L,and the remaining transformation rules used involve shorter suffixes.The basic idea is to pre-compute shortest paths in the subgraph of G which only uses transformation rules involving shorter suffixes.Specifically,let G l be the analogue of the graph G defined above on strings of length l (note that the edges of this graph correspond to the transformation rules involving suffixes of length at most l),and let D l(x,y)be the length of a shortest path from a string x to a string y(both of length l)in G l.Consider a weighted directed graph H l consisting of strings of length l,where the edges are as follows:•There is an edge from x to y of cost1if there is a transformation rule transforming x to y•There is an edge from x to y of cost D l−1(x ,y )if thefirst two charactes of x and y are equal and x ,y denote the suffixes of x and y obtained by removing thefirst character. Then,the shortest path lengths in H l are exactly the same as those in G l.In other words, D l(x,y)is given by the length of a shortest path from x to y in H l.So,one(seemingly awkward)way of computing the shortest path from S to T in G(i.e.,D L(S,T))is to iteratively compute the shortest path lengths in H l for l from1to L(since the definition of H l involve the shortest path lengts in H l−1).Now,how does this help?The number of vertices of H l is still52l!Recall that the quantity that we are actually interested in is D L(S,T).Note that to compute this,the only vertices of H L which are relevant,apart from S and T themselves,are those which occur as either lefthand or righthand side of some transformation rule.More generally,unwinding the definitions,one sees that the only vertices in H l(i.e.,the only strings of length l)that one has to consider are those which are suffixes of one of the2R+2input strings.With this good bound on the effective sizes of the graphs,computing all the relevant shortest paths lengths in H l can be done using e.g.Floyd-Warshall.A somewhat tricky point in this problem is that the length of a path can be exponentially large in the length of a string,so it may be the case that an answer does notfit in a32-bit integer.。
国际大学生程序设计大赛(ACMICPC)简介及竞赛样题

国际大学生程序设计大赛(ACMICPC)简介及竞赛样题附件二国际大学生程序设计大赛(ACM/ICPC)简介相关情况简介一>、历届ACM-ICPC亚洲预选赛中国内地部分赛区参赛情况二>、历届ACM-ICPC全球总决赛中国内地高校获奖情况注:***金牌,**银牌,*铜牌;--表示未参加上一年的地区预赛,/ 表示上一年的地区预赛未能出线。
ACM/ICPC大赛简介ACM/ICPC (ACM International Collegiate Programming Contest, 国际大学生程序设计竞赛)是由国际计算机界历史悠久、颇具权威性的组织ACM(Association for Computing Machinery,国际计算机协会)主办的,是世界上公认的规模最大、水平最高的国际大学生程序设计竞赛,是一项旨在展示大学生创新能力、团队精神和在压力下编写程序、分析和解决问题能力的年度竞赛。
其目的旨在使大学生运用计算机来充分展示自己分析问题和解决问题的能力。
该项竞赛从1970年至今已举办了34届,受到国际各知名大学的普遍重视,并受到全世界各著名计算机公司的高度关注,是信息企业与世界顶尖计算机人才对话的最好机会。
ACM国际大学生程序设计竞赛已成为世界各国大学生最具影响力的国际计算机类的赛事,是广大爱好计算机编程的大学生展示才华的舞台,是各个大学计算机教育成果的直接体现。
在过去十几年中,世界著名信息企业APPLE、AT&T、MICROSOFT和IBM分别担任了竞赛的赞助商。
中国大陆高校从1996年开始参加ACM/ICPC亚洲预赛,主要是各个重点院校。
该项竞赛分为区域预赛和国际决赛两个阶段进行,各预赛区第一名自动获得参加世界决赛的资格,世界决赛安排在每年的3~4月举行,而区域预赛安排在上一年的9~12月在各大洲举行。
ACM/ICPC的区域预赛是规模很大、范围很广的赛事,但历届河南省各高校却极少组队参加,为了提升和检验河南省计算机教育水平,河南省计算机学会从2008年开始,在河南省推广开展ACM国际大学生程序设计竞赛,为广大的爱好计算机编程的大学生提供展示才华的舞台,为河南省各高校组队参加ACM/ICPC的区域预赛的提供实战的场地,并以此为契机推动河南省计算机教育水平的提高。
2017-2018 icpc central quarter final 题解

2017-2018 icpc central quarter final题解引言概述:2017-2018 ICPC中央四分之一决赛是一场国际大学生程序设计竞赛,吸引了来自世界各地的顶尖选手参与。
本文将为大家详细解析比赛中的题目,并提供相应的解题思路和方法。
正文内容:1. 第一大点:题目一1.1 小点一:题目描述- 描述题目的要求和限制条件1.2 小点二:解题思路- 分析题目的难点和关键点- 提供解题思路和方法1.3 小点三:具体实现- 给出具体的代码实现方法或算法步骤2. 第二大点:题目二2.1 小点一:题目描述- 描述题目的要求和限制条件2.2 小点二:解题思路- 分析题目的难点和关键点- 提供解题思路和方法2.3 小点三:具体实现- 给出具体的代码实现方法或算法步骤3. 第三大点:题目三3.1 小点一:题目描述- 描述题目的要求和限制条件3.2 小点二:解题思路- 分析题目的难点和关键点- 提供解题思路和方法3.3 小点三:具体实现- 给出具体的代码实现方法或算法步骤4. 第四大点:题目四4.1 小点一:题目描述- 描述题目的要求和限制条件4.2 小点二:解题思路- 分析题目的难点和关键点- 提供解题思路和方法4.3 小点三:具体实现- 给出具体的代码实现方法或算法步骤5. 第五大点:题目五5.1 小点一:题目描述- 描述题目的要求和限制条件5.2 小点二:解题思路- 分析题目的难点和关键点- 提供解题思路和方法5.3 小点三:具体实现- 给出具体的代码实现方法或算法步骤总结:在本次2017-2018 ICPC中央四分之一决赛中,我们详细解析了五个题目,并提供了相应的解题思路和方法。
通过分析题目的要求和限制条件,我们提供了针对每个题目的具体实现步骤和代码实现方法。
通过参与这场竞赛,我们不仅提高了自己的编程能力,还学习了解决复杂问题的方法和技巧。
希望这些题解能够对大家在竞赛中遇到的类似问题有所帮助,并激发大家对程序设计的兴趣和热情。
第三十届ACMICPC 世界总决赛题目解析

第三十届ACM/ICPC 世界总决赛题目解析斯坦福大学王颖本次比赛的题目请见/icpc/Finals/2006WorldFinalProblemSet.pdf Problem A本题的大意是,给出一些机票,每个机票都是一条路线,比如城市A->城市B->城市K->…->城市N,并且每张机票有一个价格。
我们可以只用一张机票的一部分,比如城市A->城市B->城市K,然后就丢弃这张机票。
但有两个条件,第一,必须在机票的起始城市才能使用机票,也就是说,我们不能用上面的机票从城市B到城市K;第二,如果使用了一张机票的部分,以后就不能使用剩下的部分。
现在给出一条路线,我们要按顺序访问一系列的城市。
给出所有可以购买的机票,每种机票可以买无限张,问怎样可以用最少的花费完成整个旅途。
本题的数据规模颇小,机票最多20种,而每个机票最多经过10个城市。
由于机票可以重复购买,城市必须按顺序经过,很容易想到要用动态规划。
但从比赛过程中可以发现,无数的队伍被这题卡住了,而且很少的队伍能够一次通过。
问题就在于,并不是只能访问指定路径上的城市,而是可以访问一些辅助的城市来减小花费。
所以,我们要用一个二元组(i,j)来表示一个状态。
其中i表示指定路径上已经按顺序访问了的城市数量,j表示当前所在城市。
通过机票的信息,不难得到状态之间的一个有向图,而我们要求的其实就是一个最短路径。
注意到这个图是有圈的,所以我们不能直接用动态规划,而是需要用最短路算法。
本题初看觉得规模甚小,此时则可以发现最多能有20*10=200个城市,共可以有10*200=2000个状态,还是颇有规模的。
总结:想清楚后此题并不复杂。
但比赛时必须保持头脑清醒,分析清楚题意,才可能顺利解决此题。
比赛中虽然很多队伍做出此题,但很少有队伍一次做对,更有一些队伍一直困在这题,可见比赛中队伍普遍紧张,没能仔细的去考虑。
Problem B典型的最小费用最大流,不多说了。
ACMICPC2007世界总决赛解题报告

大概从2003年开始,世界总决赛的题目风格已经完全倒向以编程题为主的特点,对此我们早有准备。不过由于时差问题,还有几天前SRM比赛由于错两题导致Rating跌停对我信心的影响,使我比赛中一直不是很兴奋。不过比赛过程中,我们仍然坚定的采用前面提到过的常用组队模式:
当时我很希望能够借他的运气得到一个Yes,不过PC2还是不断返回WA直到最后。
后来,E题就成了我写计算几何题目的一个巨大的心理障碍,直到2个月前在Proxima的一次训练中,在队友的支持下,我终于成功通过了一个更强版本的E题(题目在UVA上,题号是11425,这题至今2009.1也还只有我和东京冠军队的marek通过)。
颁奖:
最终,华沙大学以通过8题的成绩获得冠军,Mobile Robot通过7题总用时1200分钟获得亚军。整场比赛,我们克服了开局的种种不利因素,成为全场第一支通过7题的队伍,亚军也是一个非常可喜的成绩了。由于华沙大学不来自亚洲,我们同时也获得了亚洲冠军。
224分钟:Problem D,数学题。这题本是一道很简单的数学题目,但是不知出题人怎么想的,搞了一些没有任何意义的东西,真是这次题目的一大败笔。我们开始由于没有注意三点共线的情况错了3-4次,然后由于int64越界又错了3-4次,最后错了7次才AC。这题一共浪费了1个多小时。
在BGF各一次奇怪的WA之后,我们又完全陷在了D题的陷阱之中,如果顺利的话D题只需要15分钟就可以写完,可是我们忘记考虑了D题中很多的阴险情况,拖延了1个多小时,贡献了7个莫名其妙的WA。可是,当时我并没有想到,这已经是我AC的最后一道题目了。
比赛开始时,正常情况我会从B-I中间寻找容易上手的题目。可是由于有些紧张,直到geworm给我翻译A题目内容时,我还没有读懂任何题目,这种情况很少发生。
ACM新生赛题目解题报告2

Hosted by 计算机与信息科学系解题报告2012.5.1912:00~17:00本题册总共有10道题目,页数共有39页。
注意事项1、比赛网址是:。
2、可以带一切纸质材料,严禁携带U盘等电子类产品。
3、杜绝网上搜索资料和互相抄袭,如有发现,上报学校处分。
4、本测试系统采用的是window平台的服务器,int类型为4个字节,__int64为8个字节,8个字节的输出格式为printf(“%I64d\n”,n);5、有问题可以举手找志愿者。
6、比赛结束将分发答案参考程序。
1、Be Good at GuassingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem DescriptionGive you many positive integer N (N<=23),for each N, just output N*(N+1)/2 integers in a single line, separated by space. (Don't ask me why.)For each N, the output line contains integers from 1 to N, and each just once. Again, do not ask me why, thank you. I'm so busy. But I can tell you a secret, the output has relationship with number triangle. As:(N=3)12 63 4 5See the sample for more information.InputMany lines, each line contains a positive integer N (N<=23).3426Sample Output1 2 6 3 4 51 2 9 3 10 8 4 5 6 71 2 31 2 15 3 16 14 4 17 21 13 5 18 19 20 12 6 7 8 9 10 11 解题代码#include<iostream>using namespace std;#include<fstream>#include<cstring>#include<cstdlib>#include<ctime>const int maxN = 24;int tri[maxN][maxN];int main(){int N,value,row,col,dir,i,j;while(cin>>N){memset(tri,0,sizeof(tri));row=col=1;for(value=1;value<=N;++value)tri[row++][col]=value;row=N,col=2;for(value=N+1;value<=2*N-1;++value) tri[row][col++]=value;row=N-1,col=N-1;for(value=2*N;value<=3*N-3;++value) tri[row--][col--]=value;row=2,col=2;value=3*N-2;dir=1;while(value<=N*(N+1)/2){if(1==dir)/*down one line*/{if((0==tri[row+1][col]))tri[++row][col]=value;else{dir=2;tri[row][++col]=value;}}else if(2==dir)/*right one line*/ {if((0==tri[row][col+1]))tri[row][++col]=value;else{dir=3;tri[--row][--col]=value;}}else{if((0==tri[row-1][col-1]))tri[--row][--col]=value;else{dir=1;tri[++row][col]=value;}}++value;}for(row=1;row<=N;++row){for(col=1;col<=row;++col){cout<<tri[row][col];if(!(row==N&&col==row))cout<<" ";}}cout<<endl;}return 0;}2、工院宅男Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description男女比例严重失调的工院向来不乏宅男,Jim做为茫茫一员,每天过着三点一线的生活,宿舍、饭店、教室。
20112011年ACM-ICPC协会程序设计大赛解题报告

Problem2 : 畅通工程
Output
对每个测试用例,在1行里输出最少还需要建设的道路数目。
Problem2 : 畅通工程
Sample Input
42 13 43 33 12 13 23 52 12 35 999 0 0
Sample Output
1 0 2 998
Problem2 : 畅通工程
Preparation Knowledge
表示集合的三种方式(数据结构): • 数组, • 树, • 图。
Problem2 : 畅通工程
Preparation Knowledge
A
B
C
D
E
F
Problem2 : 畅通工程
Solution
1. 2. 假设每个城市都是不相交的;(每个元素都是树根) 随着道路的连接,将连通的城市合并到同一个集合; (集合中的元素拥有同样的树根) 3. 统计出一共有多少个集合,输出结果。
Problem2 : 畅通工程
Examples
1 2 3 4 5
Problem2 : 畅通工程
Examples
1 2 3 4 5
1
1
3
4
5
1
1
3
4
3
Problem1 : ZOJ
Input
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。 1<=length<=100。
Output
对于每组输入,请输出一行,表示按照要求处理后的字符串。 具体可见样例。
Problem1 : ZOJ
Sample Input
ZZOOOJJJ ZZZZOOOOOJJJ ZOOOJJ E
2017ACM-ICPC亚洲区(南宁赛区)网络赛F题

2017ACM-ICPC亚洲区(南宁赛区)网络赛 F题
The Heaviest Non-decreasing Subsequence Problem
解题心得 1. 这个题就是一个简单的动态规划,非递减最长子序列的改版(加一个权重),只要把权重为5的改成5个权重为1的然后dp就可以解决 了,注意要用nlogn的复杂度才可以。
num[t] = Now; w[t++] = 1; } } }
ll ans = get_ans(t); printf("%lld\n",ans); return 0; }
ll now; ll t = 0; while(scanf("%lld",&now) != EOF) {
if(now < 0) continue;
else if(now < 10000) {
num[t] = now; w[t++] = 1; } else { int Now = now - 10000; for(int j=0;j<5;j++)//一个5的权重变成5个权重为1的 {
if(dp[len] <= num[i]) {
dp[++len] = num[i]; sum += w[i]; } else { int pos = upper_bound(dp,dp+len,num[i]) - dp; dp[pos] = num[i]; } } return sum; }
int main() {
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+100;
ACM第一期训练题解题报告

第一期训练题解题报告(1013、1016、1017)曾志平解题报告,就是将自己AC了的题的算法用文字/公式描述出来,并附上代码。
养成撰写解题报告的习惯,有利于加深自己对所用算法的理解和记忆,并且可以帮助后来者更快的学习ACM。
以下是第一期训练题中的思考题的解题报告。
HDU1013解题报告:题意理解:将一个正整数的各数位上数字相加,直到和为个位数为止。
注意,题目没有指定正整数的取值范围,所以可能会很大,位数可达500.算法思路:1.用char number[N]字符数据保存整数,N取个足够大的值,比如500;2.将字符串数组按元素进行求和,ASCII码的计算公式为ans +=number[i] – 48;3.如果计算出来的ans大于10,则将ans转换为字符串,转到第二步;4.否则,输出ans。
代码:int main(){char a[1000];int i, ans;while(scanf("%s", a) && a[0]!='0'){i=ans=0;while(1){while(a[i]!='\0')ans += a[i++] - 48;if(ans>9){sprintf(a, "%d", ans);i = ans = 0;}else break;}printf("%d\n", ans);}return 0;}HDU1016解题报告:题意理解:给你一个有n个节点的圆环,将数字1~n分别填入n 个节点中,要求任意两个相邻节点中的数字的和为素数。
题目指定了n的范围为0<n<20;算法思路:使用回溯法的最基本形式1.将1放入第一个节点(题目要求),进入下一个节点;2.递归:按顺序将2~n中的可用数字m放入当前节点(用for循环),如m加前一个节点中的数字为素数,则进入下一个节点,递归重复本步;若所有可用数字和前一个节点中的数字的和都不为素数,则返回递归的上一层;3.若当前节点是最后一个节点,且最后剩下的数字m和前一个节点中的数字的和,以及m+1都为素数,则从1开始依次输出各节点中的数字;否则,返回上一层递归,回到步骤2;4.直到所有的可能性都测试过了,算法终止。
ACMICPC2009世界总决赛解题报告

无论是出发前,还是在瑞典,许多同学和老师都看好Proxima,谢谢大家的关心。但是直到赛前,我们的精神状态都没有调整到最好。我由于赛前参加TopCoder个人比赛投入了大量精力,略微影响了组队比赛的感觉。另外,zzy比赛前一周精神状态也不是很好,至少我能感觉得到。
不过,赛前晚上我们休息得很好,比赛在上午10点左右拉开序幕。下面分享一下比赛的过程吧。
114分钟,F:计算几何。2Y
这题是zzy写的,至于出错一次的原因我也不很清楚。
121分钟,D:计算几何,判断包含4个圆的最小圆。1Y
其实我在此次总决赛过程中,除了E题之外都挺顺利的,D题其实有很简单的算法,远比Petr提出的方法简单,至少可以从7分钟写完就可以看出来,大家自己想一下吧,:P。
238分钟,I:模拟和数学题。1Y
I题是挺复杂的模拟题,需要一点数学知识。由于I题比较复杂,写程序过程中我有些着急,但是越着急越影响速度。现在回想起来,写I题是很重要的阶段,如果I再出任何问题,则THU此次总决赛能否获得奖牌都很难说,可以说后果不堪设想。现在还清晰记得zhouyuan每过几分钟就要提醒我一下“别着急,还有很多时间”,他当时的冷静对队伍来说很重要。
2009-ACM/ICPC瑞典总决赛之后,我的ICPC生涯已经彻底结束了。在网络上,许多同学经常问我如下一个问题,其实这个问题都很难有固定的答案,我只是根据自己的经历列举一下自己的体会。
ACM团队比赛与TopCoder个人赛事相比,对个人能力提出哪些特别的要求?
在实现复杂的I题的时候(230分钟左右),我们肯定都没有想到最终能够达到9题之多,而且最后还有19分钟剩余。
用随机算法尝试J,没有通过
虽然只有19分钟,我们并没有放弃比赛,无奈之下我使用了随机算法尝试J题,不过奇迹没有发生。J题其实不是很难,算法的关键部分我们都想到了,只是由于前面E和C两题卡得实在太惨了,实在没有时间写了,如果能够多出15分钟应该足够了,或者说,对于世界冠军队来说,35分钟足够通过J题。
2021ICPC网络赛第一场部分题解-The2021ICPCAsiaRegionalsOn。。。

2021ICPC⽹络赛第⼀场部分题解-The2021ICPCAsiaRegionalsOn。
写在前⾯本来应该6题的,结果不知道哪个铸币发了H的clar,当即把我们的思路转向三维⼏何上。
当时我们还在想这三维计算⼏何的正确率有点太⾼了还在感叹ICPC选⼿的含⾦量,直到赛后我才知道这H题的铸币出题⼈压根不想让我们知道他脑⼦⾥在想什么。
还好赛时将机位让给了队友写A,不然抄了你吗半天的三维计算⼏何最后WA那真的是⼼态炸了。
其他题倒是没啥好说的,就是这H越想越⽓,有这瞎琢磨的时间去开个B或者C说不定⼜能++rank。
真的⽓。
不过突然之间看到F。
哦,出题⼈是原*啊,那就说得通了。
A Busiest Computing Nodes队友写。
⼀开始直接交了发暴⼒TLE,后来在我想H的时候,⽤线段树维护下就过了。
这⾥要提⼀嘴lexicographic了。
由于三个⼤傻⼦都没带字典⽽且英语⽔平不够,于是直接交了个⼤⼩顺序,过了。
后来看Clar不明⽩为啥要特意说不是字典序。
赛后查了下直接笑出声。
不是你但凡提下dict我们也能懂啊。
搁这考专⼋呢。
#include <iostream>#include <cstdio>using namespace std;typedef long long LL;const LL N=100010;LL t[N*8],a[N*2];LL n,k;LL query(LL l,LL r,LL p,LL x,LL y){if(x<=l&&r<=y)return t[p];LL mid=l+r>>1;if(y<=mid)return query(l,mid,p<<1,x,y);if(x>mid)return query(mid+1,r,p<<1|1,x,y);return min(query(l,mid,p<<1,x,y),query(mid+1,r,p<<1|1,x,y));}void modify(LL l,LL r,LL p,LL x,LL y){if(l==r)return void(t[p]=y);LL mid=l+r>>1;if(x<=mid)modify(l,mid,p<<1,x,y);if(x>mid)modify(mid+1,r,p<<1|1,x,y);t[p]=min(t[p<<1],t[p<<1|1]);}int main(){scanf("%lld%lld",&k,&n);LL res=0;for(LL i=0;i<n;++i){LL arr,pro;scanf("%lld%lld",&arr,&pro);LL l=i%k+1,r=i%k+k;if(query(1,2*k,1,l,r)>arr)continue;while(l<r){LL mid=l+r>>1;if(query(1,2*k,1,l,mid)<=arr)r=mid;else l=mid+1;}modify(1,2*k,1,l,arr+pro);modify(1,2*k,1,(l+k-1)%(2*k)+1,arr+pro);res=max(res,++a[(l-1)%k+1]);}bool flag=false;for(LL i=1;i<=k;++i)if(a[i]==res)if(flag)printf(" %lld",i-1);else{printf("%lld",i-1);flag=true;}return 0;}B Convex Polygon⽐赛时候没开,回来看了下是裸的⼆维凸包。
浙江师范大学第10届ACM竞赛解题报告

第十届“北大青鸟”杯浙江师范大学程序设计竞赛解题报告(罗方炜,lfw2565295@ ,浙师大10计软)比赛概述首先是本届比赛的题目:总共11题本次比赛的提交统计:其中A,C,K相对简单,B,D,F为中等题,E,G,H为稍难题,I,J没人解出本次比赛前十名的情况:有两名同学成功解出8道,还有1名同学解出7道,6道的有些数量,同时恭喜前6名获得本次比赛的一等奖,同时前十名获得比赛奖品——T恤。
题目讲解A:Yes Or NoTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 596 Accepted: 94Description在二维平面上有两点P1(x1,y1),P2(x2,y2),现今,P1想向P2靠拢,但只能往斜上方走(x1+1,y1+1),或往斜下方走(x1+1,y1-1)。
请问P1能否抵达P2,如果可以输出Yes,否则输出No。
Input第一行为一个正整数t(t<=100),代表测试组数。
每一组测试数据:一行有四个整数x1,y1,x2,y2。
(各数值均大于等于0且小于等于100000)Output对于每一组测试数据,输出一行结果:如果P1能够抵达P2,输出Yes否则,输出NoSample Input30 0 1 10 0 2 00 0 3 0Sample OutputYesYesNoHint没忘记初中方程组就秒了这题拿下Second Blood吧~思路:此题被作为简单题,意思是从一个点A要走到另外一个点B是否可行,而行走的办法只能是两种,即从(x,y)点出发,下一步只能到(x+1,y+1)(*)或者(x+1,y-1)(**),这可以设一个方程,设(*)走了a次,(**)走了b次,那么联立以后就是x1+a+b=x2;y1+a-b=y2;那么方程就是求是否有a>=0和b>=0满足这个方程组,很多同学卡在这题是因为根本没有想到这个方法。
ACM校赛比赛题目及分析

Problem A -- 超级难题Time Limit:1000ms Memory Limit:65535KBDescriptionACM程序设计大赛是大学级别最高的脑力竞赛,素来被冠以"程序设计的奥林匹克"的尊称。
大赛自1970年开始至今已有30年历史,是世界范围内历史最悠久、规模最大的程序设计竞赛。
比赛形式是:经过校级和地区级选拔的参赛组,于指定的时间、地点参加世界级的决赛,由3个成员组成的小组应用一台计算机解决6到8个生活中的实际问题。
参赛队员必须在5小时内编完程序并进行测试和调试。
此种大赛对参赛学生的逻辑分析能力、策略制定和脑力方面具有极大的挑战性。
大赛提倡在压力较大的情况下,培养学生的创造力、团队合作精神以解决竞赛的问题,从而挑选和发掘世界上最优秀的程序设计人才竞赛的历史可以上溯到1970年,当时在美国德克萨斯A&M大学举办了首届比赛。
当时的主办方是the Alpha Chapter of the UPE Computer Science Honor Society。
作为一种全新的发现和培养计算机科学顶尖学生的方式,竞赛很快得到美国和加拿大各大学的积极响应。
1977年,在ACM计算机科学会议期间举办了首次总决赛,并演变成为目前的一年一届的多国参与的国际性比赛。
迄今已经举办了29届ACM/ICPC以团队的形式代表各学校参赛,每队由3名队员组成。
每位队员必须是入校5年内的在校学生。
比赛期间,每队使用1台电脑需要在5个小时内使用C、C++、Pascal或Java中的一种编写程序解决8或10个问题。
程序完成之后提交裁判运行,并把运行结果及时通知参赛队。
而且有趣的是每队在正确完成一题后,组织者将在其位置上升起一只代表该题颜色的气球2009年的时候队伍A参加了ACM的区域赛,那次区域赛比赛总共有N个题,队伍A做了N个题中的M个。
队伍A 做第一题所用的时间为T1分钟,做第一题所用的时间为T2分钟,.......做第M题所用的时间为Tm分钟。
ACM竞赛试题分析

上一次笔者简单地介绍了ACM/ICPC程序设计竞赛的基本信息和发展状况,这次则试着向大家展示一下其中一个比较简单的题目,并作出一些粗浅的分析,希望能以此让大家有个更感性的认识。
从“蛇和梯子”的问题谈对信息的过滤处理2002年11月2日阿拉伯和北非地区第5届地区赛题目G蛇和梯子问题简述:“蛇和梯子”是一个在N*N(0<N<=20)的方格棋盘上进行的游戏。
(见下图)方格从1到N的平方编号。
除了1号和最后1号方格,其他的格子有可能有蛇或梯子存在(蛇和梯子的数量及具体位置由输入确定,它们的数量都在100之内并且蛇和梯子不能临近放置,也就是在任何了放置两者首尾的方格之间至少还有一个未放置任何东西的格子)。
开始的时候玩家把他们的标志物放在1号格子中。
玩家轮流以扔骰子的方式移动他们的指示物。
如果一个指示物到达了一条蛇的嘴部,则把它移回蛇的尾部。
如果一个指示物到达了一个梯子的底部则将它移动到梯子的顶部。
如果你是一个可以自由控制骰子的高手,现在请求出你至少需要扔几次骰子才能到达标为N^2的格子。
(比如在上图所示例一中,你的方案应该是走4步到达5并由梯子上升到16,再走4步到达20并由梯子上升到33,然后走3步。
这样,你一共需要扔3次骰子。
而在例二中,你的方案应该是连扔4个6。
)比较容易看出,这个问题是不能用贪心算法解决的,因为你不能保证在这步到达一个数码比较大的格子就意味着最好的效率(即使是通过梯子到达了一个这步所能到达的最大号码的格子),也就是说,号码的大小并不能代表从这个格子到达终点所需要的步数上的多少,这就带给我们一个启发:蛇和梯子真的需要看成是两个东西来分别处理么?实际上确实是不需要的,蛇和梯子的本质就是我们经常在游戏中说的“单向传送点”,只不过梯子的底部是入口而顶部是出口,蛇的嘴部是入口而尾部是出口罢了,对于他们的描述完全可以选择相同的结构:struct SnakeAndLadder{int from,to;};接下来要考虑的是解决问题的方法。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
ZOJZOJOJ ZOJZOJZOJZOO ZOJOJO
Problem1 : ZOJ
Analysis
要将字符串按照 ZOJ 的顺序输出,只需要记 录字符 ‘Z’、’O’、’J’ 各自在字符串中出现的 次数即可。
Problem1 : ZOJ
Solution
1. 输入字符串; 2. 分析字符串,分别记录字符 ‘Z’ , ‘O’ , ‘J’ 出现的次数; 3. 输出结果。
Problem1 : ZOJ
Beginner’s Guide
解题格式; Input 和 Output 的格式; 不管通过何种方式实现,只需输出正确答案。
Problem2 : 畅通工程
Problem2 : 畅通工程
Description
某省调查城镇交通状况,得到现有城镇道路统计表,表中 列出了每条道路直接连通的城镇。省政府“畅通工程”的目 标是使全省任何两个城镇间都可以实现交通(但不一定有 直接的道路相连,只要互相间接通过道路可达即可)。问 最少还需要建设多少条道路?
Problem1 : ZOJ
Input
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。 1<=length<=100。
Output
对于每组输入,请输出一行,表示按照要求处理后的字符串。 具体可见样例。
Problem1 : ZOJ
Sample Input
ZZOOOJJJ ZZZZOOOOOJJJ ZOOOJJ E
Solution
1. 假设每个城市都是不相交的;(每个元素都是树根) 2. 随着道路的连接,将连通的城市合并到同一个集合;
(集合中的元素拥有同样的树根) 3. 统计出一共有多少个集合,输出结果。
Problem2 : 畅通工程
Examples
1
2
3
4
5
Problem2 : 畅通工程
Examples
找出 n 个互不相交的城镇集合,结果就为 n – 1。
Problem2 : 畅通工程
Preparation Knowledge
表示集合的三种方式(数据结构): • 数组, • 树, • 图。
Problem2 : 畅通工程
Preparation Knowledge
A
B
C
D
E
F
Problem2 : 畅通工程
Sample Output
1 0 2 998
Problem2 : 畅通工程
Analysis
Case 1:
1
2
3
4
Problem2 : 畅通工程
Analysis
Case 2:
1
2
3
Problem2 : 畅通工程
Analysis
Case 3:
1
2
3
4
5
Problem2 : 畅通工程
Key Point
1
2
3
4
5
1
1
3
4
5
1
1
3
4
3
2011年ACM-ICPC协会程序设计 大赛解题报告(part1)
1 : ZOJ
Problem1 : ZOJ
Description
读入一个字符串,字符串中包含ZOJ三个字符,个 数不一定相等,按ZOJ的顺序输出,当某个字符用 完时,剩下的仍然按照ZOJ的顺序输出。
33 12 12 21 这种输入也是合法的 当N为0时,输入结束,该用例不被处理。
Problem2 : 畅通工程
Output
对每个测试用例,在1行里输出最少还需要建设的道路数目。
Problem2 : 畅通工程
Sample Input
42 13 43 33 12 13 23 52 12 35 999 0 0
Problem2 : 畅通工程
Input
测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目( N < 1000 ) 和道路数目M;随后的M行对应M条道路,每行给出一对正整数,分别是该条道路直接 连通的两个城镇的编号。为简单起见,城镇从1到N编号。 注意:两个城市之间可以有多条道路相通,也就是说