Codeforces Round #298 (Div. 2) A、B、C题
题目链接:Codeforces Round #298 (Div. 2)
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.
A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.
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 ;
}
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.
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.
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 ;
}
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.
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.
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题的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- 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 ...
- Codeforces Round #298 (Div. 2) D. Handshakes 构造
D. Handshakes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #298 (Div. 2) B. Covered Path
题目大意: 一辆车,每秒内的速度恒定...第I秒到第I+1秒的速度变化不超过D.初始速度为V1,末速度为V2,经过时间t,问最远能走多远. 分析 开始的时候想麻烦了.讨论了各种情况.后来发现每个时刻的 ...
- CodeForces Round #298 Div.2
A. Exam 果然,并没有3分钟秒掉水题的能力,=_=|| n <= 4的时候特判.n >= 5的时候将奇数和偶数分开输出即可保证相邻的两数不处在相邻的位置. #include < ...
- Codeforces Round #298 (Div. 2)--D. Handshakes
#include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...
随机推荐
- mysql破解密码安装与基本管理
一.MySQL介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是 ...
- P1880 石子合并
P1880 石子合并 题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计 ...
- RF、GBDT、XGBOOST常见面试算法整理
1. RF(随机森林)与GBDT之间的区别 相同点: 1)都是由多棵树组成的 2)最终的结果都是由多棵树一起决定 不同点: 1) 组成随机森林的树可以是分类树也可以是回归树,而GBDT只由回归树组 ...
- python学习_常用语句
1.变量 1 name='hu qihang' #变量名应为英文,方便阅读 2 name_of_gf='chen ye' #多个单词用下划线隔开 3 名字='hu qihang' #变量名可以是中文 ...
- BZOJ 1877:[SDOI2009]晨跑(最小费用最大流)
晨跑DescriptionElaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个 ...
- Teleportation(tel)
Teleportation(tel) 题目描述 Zy大帝拥有n个星球,因为距离非常遥远,所以Zy在他所居住的1号星球和他的军事基地霸中所在的2号星球建造了两个传送门,这样从1号星球到2号星球就只需要2 ...
- 笔记:CS231n+assignment2(作业二)(一)
第二个作业难度很高,但做(抄)完之后收获还是很大的.... 一.Fully-Connected Neural Nets 首先是对之前的神经网络的程序进行重构,目的是可以构建任意大小的全连接的neura ...
- Codeforces Round #362 (Div. 2) B 模拟
B. Barnicle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- kubernetes 数据持久化之Glusterfs
1.GlusterFS 部署过程请参考上篇文章 2.配置endpoints [root@manager ~]# cat glusterfs-endpoints.json { "kind&q ...
- iOS 代理为啥要用weak修饰?
在开发中我们经常使用代理,或自己写个代理,而代理属性都用weak(assign)修饰,看过有些开发者用strong(retain),但并没发现有何不妥,也不清楚weak(assign)与strong( ...