题目链接:Codeforces Round #298 (Div. 2)

A. Exam

An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.

Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

Input

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

Output

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.

In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 tok - 1.

If there are several possible answers, output any of them.

题意描述:给出n个学生,编号为1~n,要求学生坐在一排并且相邻的学生编号相差不能为1,求出满足这样要求的最大学生数量并输出方案。

算法分析:对于一个大于4的数字,我们可以把它的奇数放在前面,把偶数放在后面,这样很显然不会出现相邻的数字差值为1,然后特判一下1,2,3,4的情况即可。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std; int n; int main()
{
while (scanf("%d",&n)!=EOF)
{
if (n==) {printf("1\n1\n");continue; }
if (n==) {printf("1\n1\n");continue; }
if (n==) {printf("2\n1 3\n");continue; }
if (n==) {printf("4\n2 4 1 3\n");continue; }
printf("%d\n",n);
printf("");
for (int i= ;i<=n ;i+=) printf(" %d",i);
for (int i= ;i<=n ;i+=) printf(" %d",i);
printf("\n");
}
return ;
}

B. Covered Path

The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.

Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.

Input

The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.

It is guaranteed that there is a way to complete the segment so that:

  • the speed in the first second equals v1,
  • the speed in the last second equals v2,
  • the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.
Output

Print the maximum possible length of the path segment in meters.

题意描述:给出初速度v1和末速度v2、运动时间t和相邻秒数之间速度可以增长的最大值d,每一秒钟我们看作速度不变,在秒数之间的速度变化可以看作是瞬间的(即第一秒的速度5,在允许增长的前提下,我们可以看作第二秒的速度已经是8),求出行驶的最远长度。

算法分析:这道题很简单,但在做的时候还是有点绕的。我们首先分析v1和v2的情况:

v1 < v2 :然后还得分两种情况:v1在t秒刚好增长到v2;v1在s(s<t)秒增长到v2,然后在s~t之间先增长后降低。前者速度曲线是直线向上,后者速度曲线是先增长到一个峰值,然后下降。

v1 == v2 :这种情况直接和v1<v2中第二种情形s~t秒内一样。

v1 > v2 :和第一种情况相反。我们从v2到v1这样看,就是和第一种情况一样了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int n;
int v1,v2,t,d; int main()
{
while (scanf("%d%d%d%d",&v1,&v2,&t,&d)!=EOF)
{
int ans=;
int q=,h=t;
if (v1<v2)
{
while (q<=h)
{
ans += v1;
v1 += d;
q++;
if (q==h) v1=v2;
else if (abs(v1-v2)<=d) break;
}
if (q>=h) {printf("%d\n",ans);continue; }
for ( ;q<h ;q++,h--)
{
ans += v1;
ans += v2;
v1 += d;
v2 += d;
}
if (q==h) ans += min(v1,v2);
printf("%d\n",ans);
}
else if (v1>v2)
{
while (q<=h)
{
ans += v2;
v2 += d;
h--;
if (h==q) v2=v1;
else if (abs(v1-v2)<=d) break;
}
if (q>h) {printf("%d\n",ans);continue; }
for ( ;q<h ;q++,h--)
{
ans += v1;
ans += v2;
v1 += d;
v2 += d;
}
if (q==h) ans += min(v1,v2);
printf("%d\n",ans);
}
else
{
for ( ;q<h ;q++,h--)
{
ans += v1;
ans += v2;
v1 += d;
v2 += d;
}
if (q==h) ans += min(v1,v2);
printf("%d\n",ans);
}
}
return ;
}

C. Polycarpus' Dice

Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).

For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.

Input

The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.

The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show.

Output

Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.

题意描述:有n个骰子d1,d2,,,,dn,第i个骰子有di面(值为1~di),通过n个骰子摇出一个值A,然后求出每个骰子不可能出现的值的个数。

算法分析:如果有5个骰子,前4个骰子最小值的和为4,最大值的和为10,现在摇出的值A为13,那么第5个骰子出现的最小值必须得是3,最大值为9。根据每个骰子都这样的想法,然后就可以AC了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
typedef long long LL;
const LL maxn=+; LL n,A;
LL an[maxn]; int main()
{
while (scanf("%I64d%I64d",&n,&A)!=EOF)
{
LL sum=;
for (LL i= ;i<=n ;i++)
{
scanf("%I64d",&an[i]);
sum += an[i];
}
LL l=n-;
for (LL i= ;i<=n ;i++)
{
l=n-;
LL r=sum-an[i];
LL right=A-l;
LL left= r>=A ? : A-r;
LL num=right-left+;
if (i>) printf(" ");
if (right<=an[i]) printf("%d",an[i]-num);
else if (left<=an[i] && an[i]<right) printf("%d",left-);
else printf("%d",an[i]);
}
printf("\n");
}
return ;
}

Codeforces Round #298 (Div. 2) A、B、C题的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #298 (Div. 2) E. Berland Local Positioning System 构造

    E. Berland Local Positioning System Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  3. Codeforces Round #298 (Div. 2) D. Handshakes 构造

    D. Handshakes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...

  4. Codeforces Round #298 (Div. 2) C. Polycarpus' Dice 数学

    C. Polycarpus' Dice Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/p ...

  5. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  6. Codeforces Round #298 (Div. 2) A. Exam 构造

    A. Exam Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/A Des ...

  7. Codeforces Round #298 (Div. 2) B. Covered Path

    题目大意: 一辆车,每秒内的速度恒定...第I秒到第I+1秒的速度变化不超过D.初始速度为V1,末速度为V2,经过时间t,问最远能走多远. 分析 开始的时候想麻烦了.讨论了各种情况.后来发现每个时刻的 ...

  8. CodeForces Round #298 Div.2

    A. Exam 果然,并没有3分钟秒掉水题的能力,=_=|| n <= 4的时候特判.n >= 5的时候将奇数和偶数分开输出即可保证相邻的两数不处在相邻的位置. #include < ...

  9. Codeforces Round #298 (Div. 2)--D. Handshakes

    #include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...

随机推荐

  1. input框中的必填项之取消当前input框为必填项

    html5新增了一个required属性,可以使用这个属性对文本框设置必填项,直接在input文本框上添加required即可 . 效果如图:   

  2. 理解机器为什么可以学习(二)---Training versus Testing

    前边由Hoeffding出发讨论了为什么机器可以学习,主要就是在N很大的时候Ein PAC Eout,选择较小的Ein,这样的Eout也较小,但是当时还有一个问题没有解决,就是当时的假设的h的集合是个 ...

  3. rule.xml属性概念

    # tableRule <tableRule name="rule1"> <rule> <columns>id</columns> ...

  4. ABP 未能加载文件或程序集“System.ComponentModel.Annota, Version=4.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。

    切换System.ComponentModel.Annotations版本到4.4.1  重新编译即可

  5. 【bzoj3998】[TJOI2015]弦论 后缀自动机+dp

    题目描述 对于一个给定长度为N的字符串,求它的第K小子串是什么. 输入 第一行是一个仅由小写英文字母构成的字符串S 第二行为两个整数T和K,T为0则表示不同位置的相同子串算作一个.T=1则表示不同位置 ...

  6. hihoCoder 1467 2-SAT·hihoCoder音乐节(2-SAT模版)

    #1467 : 2-SAT·hihoCoder音乐节 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 hihoCoder音乐节由hihoCoder赞助商大力主办,邀请了众 ...

  7. BZOJ3203 保护出题人(defend)

    保护出题人(defend) 题目描述 输入 第一行两个空格隔开的正整数n和d,分别表示关数和相邻僵尸间的距离. 接下来n行每行两个空格隔开的正整数,第i + 1行为 a i和 x i,分别表示相比上一 ...

  8. 【bzoj3119】Book

    小清新题,有手有笔就能做出来了…… 先把 $b$ 取相反数,这样写加法好看. 设 $x,y$,使得 $ax+by=m-np$(其实是懒得想文字定义了),该方程与 $x+y=\frac{n(n-1)}{ ...

  9. 【11】react 之 flux

    Flux 是 Facebook 使用的一套前端应用的架构模式.React 标榜自己是 MVC 里面 V 的部分,那么 Flux 就相当于添加 M 和 C 的部分. 1.1.  Flux介绍 Flux并 ...

  10. 【01】react 之 hello world

    React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设 Instagram 的网站.做出来以后,发现这套东西 ...