# Name    
A
standard input/output

1 s, 256 MB

   x6036
B
standard input/output

1 s, 256 MB

   x4139
C
standard input/output

1 s, 256 MB

   x2671
D
standard input/output

2 s, 256 MB

   x1113
E
standard input/output

1 s, 256 MB

   x247
 

A. Bachgold Problem

给出一个N,请你找出一些素数,使得素数的和为N,且素数的个数最多。注意,素数可以重复,而且N>=2。

解:显然用2和3拆喽,大家又不傻。

 VAR
n:longint;
a:longint;
i:longint;
BEGIN
readln(n);
a:=n div ;
writeln(a);
for i:= to a- do begin
write();
write(' ');
end;
write(+n mod );
END.

B. Parallelogram is Back

给出一个平行四边形的三个顶点,输出所有可能的第四个顶点。

解:小学几何问题喽,大家又不傻。

 #include <bits/stdc++.h>

 using namespace std;

 signed main(void)
{
int x1, y1;
int x2, y2;
int x3, y3;
cin >> x1 >> y1
>> x2 >> y2
>> x3 >> y3;
cout << << endl;
cout << +x1 - x2 + x3 << " " << +y1 - y2 + y3 << endl;
cout << +x1 + x2 - x3 << " " << +y1 + y2 - y3 << endl;
cout << -x1 + x2 + x3 << " " << -y1 + y2 + y3 << endl;
}

C. Voting

两个政党(D和R)的议员们在进行投票,他们的投票规则十分古怪:当前投票的议员,可以选取一个队里阵营的议员,取消他的投票权。

所有议员按照给出的顺序循环投票,最终以一个阵营的全部议员都被禁言结束,此时另一个阵营就会胜出。如果议员们都按照最优策略投票,请你模拟出投票的结果。

解:用两个队列维护两个政党的议员的位置,每次取出两个队首进行比较,位置在前的议员可以弹掉另一个队首,这个队首再也不会进队,而位置在前的议员以当前位置+n的新位置(循环)加入队尾。

 #include <bits/stdc++.h>

 using namespace std;

 int n;
string s;
queue<int> D, R; signed main(void)
{
cin >> n >> s; for (int i = ; i < n; ++i)
(s[i] == 'D' ? D : R).push(i); while (!D.empty() && !R.empty())
{
if (D.front() < R.front())
R.pop(), D.push(D.front() + n), D.pop();
else
D.pop(), R.push(R.front() + n), R.pop();
} cout << (D.empty () ? 'R' : 'D') << endl;
}

D. Leaving Auction

一些壕在拍卖会上竞拍,首先给出了大家既定的报价。一个人可能给出多次报价,但不会自己无故压自己。有Q次询问,每次一些人会离场,请把这些人的报价从序列中清除,问最后谁以什么价格赢得拍品。赢家即为最后一个报价的人,而价格为其最低的压过其他所有人(在场)的价格。如果有不理解,可以看样例。

解:首先处理出所有壕的最后一个报价,然后排序。每次询问可以暴力在序列中找到没有离场的最靠后报价的壕,那么他一定会赢得拍品,问题在于是什么价格。我们需要知道他需要压住的最后的另一位壕(如果存在),这个可以继续在序列中暴力向前扫描得到(因为总的离场人数是有限制的,而至多扫过的位置是离场人数级别的,所以复杂度有保证)。我们现在需要知道赢家壕在这位壕最后一次出价的位置之后,出的第一次价。如果事先维护了每个人的出价位置,直接在序列中二分即可,复杂度可以过。注意不要像我一样每次询问memset一遍awy数组,会TLE on test8。

 #include <bits/stdc++.h>

 #define fread_siz 1024

 inline int get_c(void)
{
static char buf[fread_siz];
static char *head = buf + fread_siz;
static char *tail = buf + fread_siz; if (head == tail)
fread(head = buf, , fread_siz, stdin); return *head++;
} inline int get_i(void)
{
register int ret = ;
register int neg = false;
register int bit = get_c(); for (; bit < ; bit = get_c())
if (bit == '-')neg ^= true; for (; bit > ; bit = get_c())
ret = ret * + bit - ; return neg ? -ret : ret;
} using namespace std; const int N = ; int n, m; int a[N], b[N]; int tot;
int vis[N];
int lst[N];
int ord[N]; int awy[N], q; vector<int> p[N]; signed main(void)
{
n = get_i(); for (int i = ; i <= n; ++i)
a[i] = get_i(),
b[i] = get_i(); for (int i = ; i <= n; ++i)
p[a[i]].push_back(i); for (int i = n; i >= ; --i)
if (!vis[a[i]])
{
vis[a[i]] = ;
lst[a[i]] = i;
ord[++tot] = a[i];
} m = get_i(); for (int i = ; i <= m; ++i)
{
q = get_i();
for (int j = ; j <= q; ++j)
awy[get_i()] = i;
int ans1 = , ans2 = , pos;
for (int j = ; j <= tot && !ans1; ++j)
if (awy[ord[j]] != i)ans1 = ord[j], pos = j;
if (!ans1)
puts("0 0");
else
{
for (++pos; pos <= tot; ++pos)
if (awy[ord[pos]] != i)break;
if (pos > tot)
printf("%d %d\n", ans1, b[p[ans1][]]);
else
{
int lim = lst[ord[pos]];
ans2 = *lower_bound(begin(p[ans1]), end(p[ans1]), lim);
printf("%d %d\n", ans1, b[ans2]);
}
}
}
}

E题看起来好烦,无限期停更,大概不会填坑。

@Author: YouSiki

Codeforces Round #388 (Div. 2)的更多相关文章

  1. Codeforces Round #388 (Div. 2) - C

    题目链接:http://codeforces.com/contest/749/problem/C 题意:给定一个长度为n的D/R序列,代表每个人的派别,然后进行发表意见,顺序是从1到n.每个人到他的回 ...

  2. Codeforces Round #388 (Div. 2) - B

    题目链接:http://codeforces.com/contest/749/problem/B 题意:给定平行四边形的3个点,输出所有可能的第四个点. 思路:枚举任意两个点形成的直线,然后利用这两个 ...

  3. Codeforces Round #388 (Div. 2) - A

    题目链接:http://codeforces.com/contest/749/problem/A 题意:给定一个数n,求把n分解成尽量多的素数相加.输入素数个数和具体方案. 思路:因为要尽量多的素数, ...

  4. Codeforces Round #388 (Div. 2) A,B,C,D

    A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)

    题目大意 给定一个1到n的排列,然后随机选取一个区间,让这个区间内的数随机改变顺序,问这样的一次操作后,该排列的逆序数的期望是多少 首先,一个随机的长度为len的排列的逆序数是(len)*(len-1 ...

  6. Codeforces Round #388 (Div. 2) D

    There are n people taking part in auction today. The rules of auction are classical. There were n bi ...

  7. Codeforces Round #388 (Div. 2) A+B+C!

    A. Bachgold Problem 任何一个数都可以由1和2组成,由于n是大于等于2的,也就是可以由2和3组成.要求最多的素数即素数越小越好,很明显2越多越好,如果n为奇数则再输出一个3即可. i ...

  8. Codeforces Round #388 (Div. 2) C. Voting

    题意:有n个人,每个人要么是属于D派要么就是R派的.从编号1开始按顺序,每个人都有一次机会可以剔除其他任何一个人(被剔除的人就不在序列中也就失去了剔除其他人的机会了):当轮完一遍后就再次从头从仅存的人 ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. jdk安装

    x86 和 x64的安装判别 [root@CentOS ~]# uname -aLinux CentOS 2.6.32-358.el6.i686 #1 SMP Thu Feb 21 21:50:49 ...

  2. 关于mysql字段时间类型timestamp默认值为当前时间问题

    今天把应用部署到AWS上发现后台修改内容提交后程序报错,经过排查发现是更新数据的时候,有张数据表中的一个timestamp类型的字段默认值变成了"0000-00-00 00:00:00.00 ...

  3. TFFS格式化到创建成功过程

    True FFS内核编程 1.格式化FLASH 即使FLASH没有和块设备驱动绑定,也可对其进行格式化. tffsDevFormat (int tffsDriveNo, int formatArg); ...

  4. 简单好记的Jdk 环境变量配置

  5. eclipse 启动到loading workbench... 自动关闭

    是由于项目没有正常关闭运行而导致"workbench.xmi"中的"persistedState"标签还保持在运行时的配置造成的. 解决方法: 找到<wo ...

  6. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

  7. RabbitMQ调试与测试工具-v1.0.1 -提供下载测试与使用

    最近几天在看RabbitMQ,所以发了两天时间写了一个调试和测试工具.方便使用. 下载地址:RabbitMQTool-V1.0.1.zip

  8. 基本shell编程【3】- 常用的工具awk\sed\sort\uniq\od

    awk awk是个很好用的东西,大量使用在linux系统分析的结果展示处理上.并且可以使用管道, input | awk ''  | output 1.首先要知道形式 awk 'command' fi ...

  9. Apache服务停止:信号灯超时时间已到,指定的网络名不再可用

    环境说明:Apache2.4.10,Windows Server 2008 R2 问题说明: apache服务用于下载文件,但是在运行一段时间后,突然挂了. 其错误提示如下所示: [error] (7 ...

  10. java日志组件介绍(common-logging,log4j,slf4j,logback )

    转自:http://www.blogjava.net/daiyongzhi/archive/2014/04/13/412364.html common-logging是apache提供的一个通用的日志 ...