题目连链接:http://codeforces.com/contest/231

A. Team
time limit per test:2 seconds
memory limit per test:256 megabytes

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.

Input

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.

Output

Print a single integer — the number of problems the friends will implement on the contest.

Sample test(s)
Input
3
1 1 0
1 1 1
1 0 0
Output
2
Input
2
1 0 0
0 1 1
Output
1
Note

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);
}
B. Magic, Wizardry and Wonders
time limit per test:2 seconds
memory limit per test:256 megabytes

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.

Input

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.

Output

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.

Sample test(s)
Input
3 3 2
Output
2 1 2 
Input
5 -4 3
Output
-1
Input
5 -4 4
Output
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]);
}
}
C. To Add or Not to Add
time limit per test:2 seconds
memory limit per test:256 megabytes

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.

Input

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.

Output

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.

Sample test(s)
Input
5 3
6 3 4 0 2
Output
3 4
Input
3 4
5 5 5
Output
3 5
Input
5 3
3 1 2 2 1
Output
4 2
Note

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);
}
D. Magic Box
time limit per test:2 seconds
memory limit per test:256 megabytes

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.

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).

Input

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.

Output

Print a single integer — the sum of all numbers on the box faces that Vasya sees.

Sample test(s)
Input
2 2 2
1 1 1
1 2 3 4 5 6
Output
12
Input
0 0 10
3 2 3
1 2 3 4 5 6
Output
4
Note

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);
}

Codeforces Round #143 (Div. 2) (ABCD 思维场)的更多相关文章

  1. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  2. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  5. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Round #412 (Div. 2)ABCD

    tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...

  7. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  8. Codeforces Round #384 (Div. 2) ABCD

    一场比较简单的div2 电脑出了点问题 所以在比赛中理论ac了ACD 除了爆int这种事情之外.. A 一个人想从a到b 移动的花费这么定义 如果初始点和到达点类型相同 就不花钱 反之花距离差的绝对值 ...

  9. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

随机推荐

  1. Laravel资料

    http://laravel-cn.com/http://www.golaravel.com/docs/4.1/quick/https://github.com/search?q=Laravel&am ...

  2. Java和C++的不同

    现在一边继续深入C++,一边学习Java,为了学习得更加透彻,不断比较两者之间的不同,以后会慢慢继续增加. 1.在多态的实现上,C++需要利用关键字virtual,而Java不需要,因为在Java中, ...

  3. 大数据笔记13:Hadoop安装之Hadoop的配置安装

    1.准备Linux环境 1.0点击VMware快捷方式,右键打开文件所在位置 -> 双击vmnetcfg.exe -> VMnet1 host-only ->修改subnet ip ...

  4. Java基础知识强化44:StringBuffer类之把数组拼接成指定格式的字符串的案例

    1. 先看案例代码如下: package cn.itcast_07; /* * 把数组拼接成一个字符串 */ public class StringBufferTest2 { public stati ...

  5. ASP.Net用jQuery ajax实现页面局部刷新

    刚开始的时候使用asp的updatepanel控件实现局部刷新,而且在本地运行正确,但是部署到服务器上就变成整个页面全部刷新了.服务器用的是Windows server2000,本地机子上用的是win ...

  6. java下tcp的socket连接

    serverDemo package cn.stat.p4.ipdemo; import java.io.IOException; import java.io.InputStream; import ...

  7. 微信支付:redirect_uri参数错误 的解决办法

    redirect_url参数错误: 报这个错误,说明你的公众号后台授权设置有问题(一般有两处) 一:检查授权目录 答:支付授权目录是网站发起请求的页面所在目录,并且必须是能通过url地址访问的(与真实 ...

  8. jquery的.detach()方法

    .detach()就是从DOM中删除所有匹配的元素. 与.remove()方法不同的是, 这个方法不会把匹配的元素从jQuery对象中删除,所有绑定的事件.附加的数据等都会保留下来,因而可以在将来再使 ...

  9. Hadoop学习历程(三、第一个程序)

    根据之前的操作,我们已经可以正常的启动Hadoop了,关于真正的集群我会在之后进行说明.现在我们来看一下第一个程序吧 1. 在eclipse上建立一个java项目 2. 将 /usr/hadoop/s ...

  10. Swift 可选类型-备

    我们先看看如下代码: var n1: Int = 10 n1 = nil         //编译错误 let str: String = nil    //编译错误 Int和String类型不能接受 ...