题目连链接: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. 世界最大射电望远镜(Arecibo)用于探測地外文明

    请看下图: 这是眼下世界最大口径(305米)射电望远镜的外观图,位于美国中西部的PuertoRico州,建成于1963年,工作波段在3厘米至1米波段范围内,正好适合用于探測地外文明(SETI)的科学研 ...

  2. Log4Qt 使用(一)

    一.下载 http://sourceforge.net/projects/log4qt/develop 二.Log4Qt介绍 Log4Qt 是Apache Log4J 的Qt移植版,所以看Log4J的 ...

  3. mevan引入容联云通讯jar

    首先从官网下载jar 然后拷贝到lib目录下 最后在pom.xml中这样写 <dependency> <groupId>cn.com</groupId> <a ...

  4. 定时改变App主题的方案

    1.将接口返回的图片缓存到本地,由于写data到本地是耗时操作,为了不阻塞主线程,可开启子线程来做此操作 dispatch_queue_t queue = dispatch_queue_create( ...

  5. nginx反向代理nginx,RealServer日志打印真实ip

    title: nginx反向代理nginx,RealServer日志打印真实ip date: 2016-05-11 19:15:37 tags: --- nginx反向代理nginx,RealServ ...

  6. linux一键安装vncserver脚本

    title: linux一键安装vncserver脚本 date: 2016-04-11 14:32:04 tags: --- linux多数情况下是作为服务器使用的,管理员一般也喜欢使用命令行来管理 ...

  7. 转载——CLR标量函数、表值函数和聚合函数(UDA)

    本节主要介绍使用CLR创建标量函数,表值函数和聚合函数. 所谓标量函数指的就是此函数只返回一个值.表值函数返回值是一个表.聚合函数是在select语句中使用的,用来聚合一个结果集,类似于Sum()或是 ...

  8. (转)JSON 之FastJson解析

    一.阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parse ...

  9. JQuery结合Ajax实现双击Table表格,使Table变成可编辑,并保存到数据库中

    本文属于原创,转载请标明出处! 近期在做项目时,要实现通过双击Table表格的TR,使Table行变成可编辑,来实现修改数据并保存到数据库中的功能,无需多说,直接贴代码吧.希望能得到各位同仁指正. f ...

  10. 轻量级jQuery工具提示插件tooltipsy使用方法

    今天想给单位的系统弄一个提示插件,懒得自己做,于是就上网百度了几个jQuery插件,挺好用的.下面以tooltipsy插件为例,说明如何使用这些插件. 一.下载 首先到tooltipsy的官网http ...