题目链接: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. ECharts的x轴和y轴均使用数值类型

    今天有个需求,就是需要ECharts的x轴和y轴都要使用数值类型,即xAxis.type和yAxis.type均为value,然后我按照我以为的方式修改了下,发现图崩了 发现问题: 然后我打开了ECh ...

  2. IOS开发---菜鸟学习之路--(十)-实现新闻详细信息浏览页面

    前面已经将了上下拉刷新 实现了上下拉刷新后我们的第一级界面就做好,接下来我们就需要实现 新闻详细信息浏览了 我个人认为一般实现新闻详细页面的方法有两种(主要是数据源的不同导致了方法的不同) 第一种是本 ...

  3. IOS开发---菜鸟学习之路--(七)-自定义UITableViewCell

    本篇将介绍如何自定义 UITableViewCell 首先选择新建文件 可以直接使用快捷键 COMMAND+n打开新建页面,然后选Objective-C class 然后选择继承之UITableVie ...

  4. 图说不为人知的IT传奇故事-5-小型机之王

    此系列文章为“图说不为人知的IT传奇故事”,各位大忙人可以在一分钟甚至几秒内了解把握整个内容,真可谓“大忙人的福利”呀!!希望各位IT界的朋友在钻研技术的同时,也能在文学.历史上有所把握.了解这些故事 ...

  5. jmeter全局变量配置:将token运用到全局(跨线程组使用变量)

    请注意元器件的执行顺序: 请将提取token的配置原件放在设置全局变量的配置元器件前面(本来是一个超级马虎的人,真是俗称“方脑壳”啊) 1.获取登录后的token(提取可以用json path Ext ...

  6. 【LoadRunner】场景执行报错“failed: WSA_IO_PENDING”

    问题:性能测试场景执行报“failed: WSA_IO_PENDING”错误 解决方法: 添加web_set_sockets_option("OVERLAPPED_SEND", & ...

  7. 四则运算UI组结对作业报告

    Github提交地址: 小组成员:陈兆庭,陈昶金: 一.编程阶段 清明节开始接触和调研关于UI设计的方法.由于两人的各方面知识储备均不足,在各种东西C#.MFC.Qt中进行调查和讨论,最终因为网上说Q ...

  8. Unity 脚本<2>

    UnityEngine; using System.Collections; public class PlayerControl : MonoBehaviour { [HideInInspector ...

  9. 节点流——FileInputStream&FileOutputStream

    import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...

  10. JMeter 性能测试进阶实战

    课程简介 本课程制作的主要目的是为了让大家快速上手 JMeter,期间穿插了大量主流项目中用到的技术,以及结合当今主流微服务技术提供了测试 Dubbo 接口.Java 工程技术具体实施方案,注重实践. ...