Codeforces-Round #340 解题报告
来源:互联网 发布:中国网络诗歌网吴扬晋 编辑:程序博客网 时间:2024/05/31 18:41
617A. Elephant
time limit per test1 second memory limit per test256 megabytes
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.
Input
The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend’s house.
Output
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
input
5
output
1
input
12
output
3
Note
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.
题目链接:cf-617A
题目大意:大象一次能走1,2,3,4,5,步。问到达x最少需要几步
题目思路:水题
以下是代码:
#include <cstdio>using namespace std;int main(){ int x; cin >> x; int ans = x / 5 + (x % 5 ? 1 : 0); cout << ans << endl; return 0;}
617B. Chocolate
time limit per test1 second memory limit per test256 megabytes
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.
Input
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.
Output
Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.
input
3
0 1 0
output
1
input
5
1 0 1 0 1
output
4
Note
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
题目链接:cf-617B
题目大意:给出一段只含01的字符串,让你分块,问你有多少种方法使得每块中有且只有1个1.
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int a[105];int main(){ int n; cin >> n; int flag = 0; long long ans = 1; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) flag = 1; //需要判断没有1的情况 } if (flag == 0) ans = 0; else { int poi = -1,poj = -1; for (int i = 0; i < n; i++) { if (a[i] == 1) { poi = i; break; } //找出第一个1的位置,因为在第一个1之前的0肯定划分在第一个1这边 } for (int j = n - 1; j >= 0; j--) { if (a[j] == 1) { poj = j; break; } //同理,找出最后一个1 } if (poi != -1 && poj != -1) { int zero = 0; for (int i = poi + 1; i <= poj; i++) //eg:如果有4个连续0,就有5种划分方式。 { if (a[i] == 0) zero++; else { ans *= zero + 1; //注意各块区域的0是相乘 zero = 0; } } } } cout << ans << endl; return 0;}
617C. Watering Flowers
time limit per test2 seconds memory limit per test256 megabytes
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
Input
The first line of the input contains integers n,
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.
Output
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
input
2 -1 0 5 3
0 2
5 2
output
6
input
4 0 0 5 0
9 4
8 3
-1 0
1 4
output
33
Note
The first sample is(
The second sample is (
题目链接:cf-617C
题目大意:给出两个圆心坐标,n个点的位置,求最小的
题目思路:
求出每个点到圆心
trick:
1.可能不需要圆1,圆2就可覆盖所有点,且值最小
2.要用long long, INF定义大一些
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;#define INF 9999999999999999 //INF定义大一些struct node{ long long x,y,r1,r2;}p[2005];long long dist(long long x1,long long y1,long long x2,long long y2){ return (y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1);}int main(){ int n; long long x1,y1,x2,y2; cin >> n >> x1 >> y1 >> x2 >> y2; for (int i = 0; i < n; i++) { cin >> p[i].x >> p[i].y; p[i].r1 = dist(p[i].x,p[i].y,x1,y1); //算出各点到圆1,圆2圆心的距离 p[i].r2 = dist(p[i].x,p[i].y,x2,y2); } long long ans = INF; long long r1,r2; for (int i = 0; i < n; i++) //必有圆1,然后求出对应r2最小值。 { r1 = p[i].r1,r2 = 0; for (int j = 0; j < n; j++) { if (p[j].r1 > r1) r2 = max(r2,p[j].r2); } ans = min(r1 + r2,ans); } r2 = 0; for (int i = 0; i < n; i++) //考虑没有圆1d额情况 { r2 = max(p[i].r2,r2); } cout << min(ans,r2) << endl; return 0;}
617D. Polyline
time limit per test1 second memory limit per test256 megabytes
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.
Input
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.
Output
Print a single number — the minimum possible number of segments of the polyline.
input
1 -1
1 1
1 2
output
1
input
-1 -1
-1 3
4 3
output
2
input
1 1
2 3
3 2
output
3
Note
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:
题目链接:cf-617D
题目大意:给你3个点,问最少有几条折线,线只能是横着或者竖着。
题目思路:直接暴力。
ans = 1: 如果三个x都相同,并且三个y都相同ans = 2: 如果任意两个x相同,并且另一个点的y>=这两个点y的最大值||小于等于这两个点y的最小值ans = 3: 其余情况
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int main(){ long long x[5],y[5]; for(int i = 0; i < 3; i++) { cin >> x[i] >> y[i]; } int ans = 0; if ((x[0] == x[1] && x[1] == x[2]) || (y[0] == y[1] && y[1] == y[2])) ans = 1; else { for (int i = 0; i < 3; i++) { int j = (i + 1) % 3, k = (i + 2) % 3; if (x[i] == x[j] && (y[k] >= max(y[i],y[j]) || y[k] <= min(y[i],y[j]))) ans = 2; if (y[i] == y[j] && (x[k] >= max(x[i],x[j]) || x[k] <= min(x[i],x[j]))) ans = 2; } } if (!ans) ans = 3; cout << ans << endl; return 0;}
- Codeforces-Round #340 解题报告
- 【解题报告】Codeforces Round #340 (Div. 2)
- CodeForces Round#35解题报告
- Codeforces Round #277.5 解题报告
- codeforces round 207 解题报告
- codeforces round 209 解题报告
- codeforces round 205 解题报告
- Codeforces Round #409 解题报告
- Codeforces Round #340 (Div. 2) 完整解题报告
- Codeforces Beta Round #29 ACD解题报告
- Codeforces Beta Round #34解题报告
- CodeForces Round#34 ABCD解题报告
- Codeforces Round #149 (Div. 2)解题报告
- Codeforces Round #180 (Div. 2) 解题报告
- Codeforces Round #190 (Div. 2) 解题报告
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #189 (Div. 2) 解题报告
- Codeforces Round #142 (Div. 2) 解题报告
- cocos2d-x 透明区域不可点击的Button
- JNA调用DLL一点小结
- Codeforces Round #271 (Div. 2) 总结
- 基于Happens-before的数据竞争方法汇总 (三)
- export 原理解析 (Shell Script)
- Codeforces-Round #340 解题报告
- Baby-Step Giant-Step 解高次同余方程(形如(a^x)%n=b,其中n为素数)
- Odd Even Linked List
- hdu 3635 Dragon Balls(并查集)
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- HDU 2859 Phalanx
- 运维小知识之nginx---nginx配置Jboss集群负载均衡
- 数据结构->图的邻接表存储(C语言)
- 英汉词典开发文件