Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Thenn lines contain three integers each, each integer is either0 or1. If the first number in the line equals1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
3
1 1 0
1 1 1
1 0 0
2
2
1 0 0
0 1 1
1
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
懒得说
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[1005][10]; int main() { int n, ans = 0; scanf("%d", &n); for(int i = 0; i < n; i++) { int cnt = 0; for(int j = 0; j < 3; j++) { scanf("%d", &a[i][j]); if(a[i][j]) cnt ++; } if(cnt >= 2) ans ++; } printf("%d\n", ans); }
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.
This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater thanl. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.
Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.
Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater thanl, the numbers on the appearing cards can be anything, no restrictions are imposed on them.
It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there weren cards, they contained integers from 1 tol, and after all magical actions he was left with a single card containing numberd.
Help Vasya to recover the initial set of cards with numbers.
The single line contains three space-separated integers:n (2 ≤ n ≤ 100) — the initial number of cards on the table,d (|d| ≤ 104) — the number on the card that was left on the table after all the magical actions, andl (1 ≤ l ≤ 100) — the limits for the initial integers.
If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containingn integers from 1 tol. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.
3 3 2
2 1 2
5 -4 3
-1
5 -4 4
2 4 1 4 1
题目大意:n个数字,要求得到d分。每一个数字最大为l,规则是拿倒数第二个数减去最后一个数得到一个新的数放到最后,以此类推直到仅仅剩一个数。这个数就是最后得分,如今要构造这个初始的数字序列
题目分析:如果n为5,d=a1- (a2-(a3-(a4-a5)))化简即d=a1-a2+a3-a4+a5。从第一个数開始一加一减,我们能够通过一直移项尽量使这个等式成立
d1=a1-d =a2-a3+a4-a5 若d大于0,a1取最大即l,若d1小于0,a1取最小值即1 (下面d的取值规则同样)
d2=a2-d1=a3-a4+a5
d3=a3-d2=a4-a5
d4=a4-d3=a5
这样就能够啦。最后的a5=d4
由于a是有范围的,假设最后的a值在范围之外则不可能,由于我们选数的宗旨就是让两边尽可能相等
#include <cstdio> int ans[105]; int main() { int n, d, l; scanf("%d %d %d", &n, &d, &l); for(int i = 0; i < n - 1; i ++) { ans[i] = d > 0 ? l : 1; d = ans[i] - d; } ans[n - 1] = d; if(ans[n - 1] > l || ans[n - 1] < 1) printf("-1\n"); else { for(int i = 0; i < n - 1; i++) printf("%d ", ans[i]); printf("%d\n", ans[n - 1]); } }
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.
However, before looking for such number, you are allowed to perform not more thank following operations — choose an arbitrary element from the array and add1 to it. In other words, you are allowed to increase some array element by1 no more thank times (you are allowed to increase the same element of the array multiple times).
Your task is to find the maximum number of occurrences of some number in the array after performing no more thank allowed operations. If there are several such numbers, your task is to find the minimum one.
The first line contains two integers n and k (1 ≤ n ≤ 105;0 ≤ k ≤ 109) — the number of elements in the array and the number of operations you are allowed to perform, correspondingly.
The third line contains a sequence of n integers a1, a2, ..., an(|ai| ≤ 109) — the initial array. The numbers in the lines are separated by single spaces.
In a single line print two numbers — the maximum number of occurrences of some number in the array after at mostk allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces.
5 3
6 3 4 0 2
3 4
3 4
5 5 5
3 5
5 3
3 1 2 2 1
4 2
In the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence6, 4, 4, 0, 4, where number4 occurs 3 times.
In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array5, 5, 5, if we increase each by one, we get6, 6, 6. In both cases the maximum number of occurrences equals3. So we should do nothing, as number 5 is less than number6.
In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence3, 2, 2, 2, 2, where number2 occurs 4 times.
题目大意:给n个数a1...an。能够有k次操作。当然也能够不操作。每次操作是对当中一个数加1。同一个数能够多次被加,如今求在k次操作内得到的数字频数最大的最小数和其频数
题目分析:排序,预处理前缀和,对于每一个数向后枚举,计算在其前面第pos位的数到它这位(记为第i位),使这些数都等于a[i]须要的操作次数为
a[i] * (pos - i) - (sum[i] - sum[pos]),拿此和k比較,不断后移pos,记录答案,注意pos不能每次都从0開始,也没有这个必要,由于我们已经排过序了并且要求的是最小数,第i-1位不满足则第i位必定不满足,因此pos每次直接后移就可以
#include <cstdio> #include <algorithm> #define ll long long using namespace std; int const MAX = 1e5 + 5; ll a[MAX], sum[MAX]; int main() { int n, k; scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) scanf("%I64d", &a[i]); sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++) sum[i] = a[i] + sum[i - 1]; ll ma = 0, ans; int pos = 0; for(int i = 1; i <= n; i++) { while(i > pos && a[i] * (i - pos) - (sum[i] - sum[pos]) > k) pos ++; if(i - pos > ma) { ma = i - pos; ans = a[i]; } } printf("%I64d %I64d\n", ma, ans); }
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point(x1, y1, z1). The six faces of the box contain some numbersa1, a2, ..., a6, exactly one number right in the center of each face.
![](http://espresso.codeforces.com/383c150e64513be85e6651cf610e0f9bc05d716e.png)
The numbers are located on the box like that:
- number a1 is written on the face that lies on the ZOX plane;
- a2 is written on the face, parallel to the plane from the previous point;
- a3 is written on the face that lies on the XOY plane;
- a4 is written on the face, parallel to the plane from the previous point;
- a5 is written on the face that lies on the YOZ plane;
- a6 is written on the face, parallel to the plane from the previous point.
At the moment Vasya is looking at the box from point(x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly theai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees someai = 6, then he can't mistake this number for9 and so on).
The fist input line contains three space-separated integersx,y andz (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integersx1,y1, z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.
It is guaranteed that point (x, y, z) is located strictly outside the box.
Print a single integer — the sum of all numbers on the box faces that Vasya sees.
2 2 2
1 1 1
1 2 3 4 5 6
12
0 0 10
3 2 3
1 2 3 4 5 6
4
The first sample corresponds to perspective, depicted on the picture. Vasya sees numbersa2 (on the top face that is the darkest),a6 (on the right face that is the lightest) anda4 (on the left visible face).
In the second sample Vasya can only see number a4.
这样的A题水平的题放在D题位置,纯属恐吓人,也懒得说了
#include <cstdio> int a[7]; int main() { int x, y, z, x1, y1, z1; scanf("%d %d %d %d %d %d", &x, &y, &z, &x1, &y1, &z1); for(int i = 1; i <= 6; i++) scanf("%d", &a[i]); int ans = 0; if(y < 0) ans += a[1]; if(y - y1 > 0) ans += a[2]; if(z < 0) ans += a[3]; if(z - z1 > 0) ans += a[4]; if(x < 0) ans += a[5]; if(x - x1 > 0) ans += a[6]; printf("%d\n", ans); }