此处有目录↑
Codeforces Round #340 (Div. 2):http://codeforces.com/contest/617
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
5
1
12
3
In the first sample the elephant needs to make one step of length 5 to reach the point x.
In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.
题目大意:一头大象在x轴0处,它的朋友在x(x>0)处,大象每次移动可以走1,2,3,4,5步的长度,求大象最少移动几次
贪心即可,距离>=5时,移动长度为5,否则直达朋友家
#include <cstdio> using namespace std; int n; int main() { scanf("%d",&n); printf("%d\n",n/5+(n%5==0?0:1)); return 0; }
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.
You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't.
Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.
The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar.
The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.
Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.
3 0 1 0
1
5 1 0 1 0 1
4
In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.
In the second sample you can break the bar in four ways:
10|10|1
1|010|1
10|1|01
1|01|01
题目大意:有一段巧克力,某些点处有一个坚果,要求将其分成许多小段,每一小段只含有一处有坚果,求分割方法总数
大致思路:统计有坚果的相邻两处中没有坚果的个数为a[i],结果为Π(a[i]+1)
#include <cstdio> using namespace std; int n,a,i,cur; long long ans; bool flag=false; int main() { scanf("%d",&n); for(i=0,a=0;i<n&&a!=1;++i) scanf("%d",&a); if(i==n&&a==0)//如果全是0,则标记 flag=true; ans=cur=1; for(;i<n;++i) { scanf("%d",&a); if(a==1) { ans*=cur; cur=1; } else ++cur; } if(flag) printf("0\n"); else printf("%I64d\n",ans); return 0; }
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.
You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.
It is guaranteed that all n + 2 points in the input are distinct.
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
2 -1 0 5 3 0 2 5 2
6
4 0 0 5 0 9 4 8 3 -1 0 1 4
33
直接枚举即可,又是不看数据范围的锅,最后5min才反映过来
#include <cstdio> #include <algorithm> using namespace std; long long x[2005],y[2005],n,ans=10e17L,r1,r2; inline long long dis(long long a,long long b) { return a*a+b*b; } int main() { int i,j; scanf("%I64d",&n); scanf("%I64d%I64d%I64d%I64d",x+n,y+n,x+n+1,y+n+1); for(i=0;i<n;++i) scanf("%I64d%I64d",x+i,y+i); for(i=0;i<=n;++i) {//坐标要取到第n个,即r1半径可能为0 r1=dis(x[n]-x[i],y[n]-y[i]); r2=0; for(j=0;j<n;++j) if(dis(x[n]-x[j],y[n]-y[j])>r1)//如果第i朵花不能被喷泉1喷到 r2=max(r2,dis(x[n+1]-x[j],y[n+1]-y[j]));//半径取最大值 ans=min(ans,r1+r2); } printf("%I64d\n",ans); return 0; }
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.
Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. It is guaranteed that all points are distinct.
Print a single number — the minimum possible number of segments of the polyline.
1 -1 1 1 1 2
1
-1 -1 -1 3 4 3
2
1 1 2 3 3 2
3
The variant of the polyline in the first sample:The variant of the polyline in the second sample:The variant of the polyline in the third sample:
题目大意:共有三个点,可以通过平行于坐标轴的多段线连接起来,求多段线的最少段数
直接判别所有情况即可
#include <cstdio> #include <algorithm> using namespace std; struct Node { int x,y; }p[3]; bool cmp(const Node& a,const Node& b) { return a.x<b.x||(a.x==b.x&&a.y<b.y); } int cal() { int ans=0; for(int i=1;i<3;++i) if(p[i].x!=p[i-1].x) ++ans; if(ans==0)//如果x都相同 return 1; if(ans==1) { if(p[0].x==p[1].x) {//如果前两个x相同 if(p[0].y<p[2].y&&p[2].y<p[1].y)//第三个y值在前两个y值中间 return 3; return 2; } if(p[1].y<p[0].y&&p[0].y<p[2].y)//如果后两个x相同,并且第一个y值在后两个y值中间 return 3; return 2; } if(p[0].y==p[1].y&&p[1].y==p[2].y)//如果y值都相同 return 1; if(p[0].y==p[1].y||p[1].y==p[2].y)//如果前两个y值相同或后两个y值相同 return 2; return 3; } int main() { for(int i=0;i<3;++i) scanf("%d%d",&p[i].x,&p[i].y); sort(p,p+3,cmp); printf("%d\n",cal()); return 0; }