CodeForces Round #298 Div.2
A. Exam
果然,并没有3分钟秒掉水题的能力,=_=||
n <= 4的时候特判。n >= 5的时候将奇数和偶数分开输出即可保证相邻的两数不处在相邻的位置。
#include <bits/stdc++.h>
using namespace std; int main()
{
int n;
cin >> n;
if(n <= ) puts("1\n1");
else if(n == ) puts("2\n1 3\n");
else if(n == ) puts("4\n2 4 1 3\n");
else
{
printf("%d\n", n);
vector<int> ans;
for(int i = ; i <= n; i+=) ans.push_back(i);
for(int i = ; i <= n; i+=) ans.push_back(i);
int sz = ans.size();
for(int i = ; i < sz; i++)
{
if(i) printf(" ");
printf("%d", ans[i]);
}
puts("");
} return ;
}
代码君
B. Covered Path (贪心)
第一秒的速度为v1,第t秒的速度为v2.
因为d很小,对于中间的每一秒,从d到-d枚举下一秒速度的变化量,只要保证在剩下的时间内能够减速到v2,这个速度变化量就是合法的。
#include <bits/stdc++.h> using namespace std; int main()
{
int v1, v2, t, d;
cin >> v1 >> v2 >> t >> d; vector<int> v; v.push_back(v1);
int now = v1; //当前车速
for(int i = ; i <= t-; i++)
{
int dd;
for(dd = d; dd >= -d; dd--)
if(now + dd <= (t - i) * d + v2)
break;
now += dd;
v.push_back(now);
}
v.push_back(v2);
int s = ;
for(int i = ; i < v.size(); i++) s += v[i];
printf("%d\n", s); return ;
}
代码君
C. Polycarpus' Dice
这n个骰子的点数之和为A。
对于某一个骰子,这个骰子的点数不能过大,因为这样可能使得其他骰子点数出现0的情况。
这个骰子点数也不能过小,因为可能剩余的骰子全部置为最大点也不能使总点数为A。
从这两个方面考虑,就能计算出每个骰子不可能出现的点数有多少种。
#include <iostream>
#include <bits/stdc++.h>
using namespace std; typedef long long LL; const int maxn = + ;
LL a[maxn]; int main()
{
LL n, A, s = ;
cin >> n >> A;
for(int i = ; i < n; i++) { scanf("%I64d", &a[i]); s += a[i]; }
for(int i = ; i < n; i++)
{
if(i) printf(" ");
LL ans = ;
ans += max(0LL, a[i] + n - - A);
LL ss = s - a[i];
ans += max(0LL, A - ss - );
printf("%I64d", ans);
}
puts(""); return ;
}
代码君
D. Handshakes (贪心 模拟 链表)
要和k个人握手的人可能有多个,所以我们用一个链表把他们连接起来。
以第二个样例为例:
9
0 2 3 4 1 1 0 2 2
和0个人握手的人有:1 7
和1个人握手的人有:5 6
和2个人握手的人有:2 8 9
和3个人握手的人有:3
和4个人握手的人有:4
这样我们可以先使7 6 9 3 4入场,然后没有人要和5个人握手,但是如果这五个人有三个人结成一队的话,那么8入场会和两个人握手。
这样还剩3个人,发现没有人要和3个人握手,于是这3个人结成一队。
1 5 2依次入场。
#include <cstdio> const int maxn = + ; int repr[maxn], next[maxn], a[maxn]; int main()
{
//freopen("in.txt", "r", stdin); int n; scanf("%d", &n);
for(int id = ; id <= n; id++)
{//id为和x个人握手的链表的编号
int x; scanf("%d", &x);
next[id] = repr[x]; //将id插入和x个人握手的链表的头部
repr[x] = id; //修改头指针
} int p = , now = ;
while(repr[now])
{
a[p++] = repr[now];
repr[now] = next[repr[now]]; //这个人已入场,修改头指针,相当于将其从链表中删除
now++;
while(repr[now] == && now >= ) now -= ;
}
if(p == n)
{
puts("Possible");
for(int i = ; i < n-; i++) printf("%d ", a[i]);
printf("%d\n", a[n-]);
}
else puts("Impossible"); return ;
}
代码君
CodeForces Round #298 Div.2的更多相关文章
- Codeforces Round #298 (Div. 2) A、B、C题
题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...
- 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)--D. Handshakes
#include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...
- Codeforces Round #298 (Div. 2)A B C D
A. Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
随机推荐
- 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件
作者:Sreekanth Mothukuru 2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 AP ...
- POJ 2591 1338 2545 2247(数列递归衍生问题,思路挺妙)
四道题的难度: 2591<1338<2545<2247 POJ 2591 Set Definition: 这是从discuss里看来的,写的挺好,直接copy,根据我的代码稍有改动( ...
- 详解 $_SERVER 函数中QUERY_STRING和REQUEST_URI区别
详解 $_SERVER 函数中QUERY_STRING和REQUEST_URI区别 http://blog.sina.com.cn/s/blog_686999de0100jgda.html 实例: ...
- POJ 1144 Network(Tarjan)
题目链接 题意 : 找出割点个数. 思路 : Tarjan缩点,u是割点的充要条件是:u要么是具有两个以上子女的深度优先生成树的根,要么不是根,而有一个子女v满足low[v]>=dfn[u]. ...
- POJ 3034 Whac-a-Mole(DP)
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...
- node.js的npm详解
一.什么是npm呢 npm(Node Package Manager,node包管理器)是node的包管理器,他允许开发人员在node.js应用程序中创建,共享并重用模块.模块就是可以在不同的项目中重 ...
- Ajax的进阶学习(一)
在Ajax课程中,我们了解了最基本的异步处理方式.本章,我们将了解一下Ajax的一些全局请求事件.跨域处理和其他一些问题. 加载请求 在Ajax异步发送请求时,遇到网速较慢的情况,就会出现请求时间较长 ...
- http://blog.csdn.net/wxwzy738/article/details/16968767
http://blog.csdn.net/wxwzy738/article/details/16968767
- 查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊
1.查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊 2.Tomcat服务器和虚拟机的关系,Tomcat启动运行过程要调用系统环境变量的java_home啊,J ...
- Spring框架学习之第3节
model层(业务层+dao层+持久层) spring开发提倡接口编程,配合di技术可以更好的达到层与层之间的解耦 举例: 现在我们体验一下spring的di配合接口编程,完成一个字母大小写转换的案例 ...