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的更多相关文章

  1. 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 ...

  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)--D. Handshakes

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

  9. 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 ...

随机推荐

  1. hive的学习入门(飞进数据仓库的小蜜蜂)

    前言 hive是构建在Hadoop上的数据仓库平台,其设计目标是:使Hadoop上的数据操作与传统的SQL结合,让熟悉sql的开发人员能够轻松的像Hadoop平台迁移. Hive是Facebook的信 ...

  2. 用fabric部署维护kle日志收集系统

    最近搞了一个logstash kafka elasticsearch kibana 整合部署的日志收集系统.部署参考lagstash + elasticsearch + kibana 3 + kafk ...

  3. 如何在Asp.net中备份Access数据库?

    public   void   Create(   string   mdbPath   ) { if(   File.Exists(mdbPath)   )   //检查数据库是否已存在 { thr ...

  4. 利用excel数据透视表实现快速统计相关数据

    昨天ytkah在做数据报表时需要做一些具体统计数字:公司每天都有人申请铅笔.笔记本等一些文具用品,现在想要统计每天申请铅笔多少支.笔记本多少本,如下图所示,这个要如何实现呢? excel数据透视表怎么 ...

  5. SWF Web播放器

    <HTML> <HEAD> <!-- saved from url=(0013)about:internet --> <TITLE> Untitled. ...

  6. C# 对动态编辑的一些学习笔记

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Comp ...

  7. Android开发者:你真的会用AsyncTask吗?

    [导读]在Android应用开发的过程中,我们需要时刻注意保证应用程序的稳定和UI操作响应及时,因为不稳定或响应缓慢的应用将给应用带来不好的印象,严重的用户卸载你的APP,这样你的努力就没有体现的价值 ...

  8. HDU 2674 N!Again(数学思维水题)

    题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...

  9. PATH环境变量和CLASSPATH环境变量详解

    大凡装过JDK的人都知道要安装完成后要设置环境变量,可是为什么要设置环境变量呢?环境变量有什么作用? 1)PATH详解: 计算机安装JDK之后,输入“javac”“java”之类的命令是不能马上被计算 ...

  10. Windows 7 常用快捷键 命令

    Win+E:  打开新的windows资源浏览器 Win+F:搜索文件或文件夹 Win+R:打开运行窗口 Win + D:显示桌面 Win + M:最小化所有窗口 Ctrl+Shift+N: 新建文件 ...