Codeforces Round #469 Div. 2 A B C D E
A. Left-handers, Right-handers and Ambidexters
题意
\(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可。要组成一支队伍,里面用左手的人数与用右手的人数相等,问队伍最大人数。
Code
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long LL;
int main() {
int l,r,a;
scanf("%d%d%d", &l,&r,&a);
if (l-r>=a) printf("%d\n", r+a<<1);
else if (r-l>=a) printf("%d\n", l+a<<1);
else {
int z=l-r;
if ((z+a)&1) --a;
int y=(z+a)>>1, x=a-y;
printf("%d\n", (l+x)*2);
}
return 0;
}
B. Intercepted Message
题意
两个序列\(a,b\),总和相等,将\(a,b\)分别切成\(k\)段,对应段的子序列和相等。问最多能切成多少段。
思路
贪心
Code
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
#define maxn 1000010
using namespace std;
int a[maxn], b[maxn];
typedef long long LL;
int main() {
int n,m;
LL s1=0, s2=0;
scanf("%d%d",&n,&m);
F(i, 0, n) scanf("%d", &a[i]);
F(i, 0, m) scanf("%d", &b[i]);
int i=0, j=0, tot=-1;
while (true) {
if (s1==s2) {
++tot;
if (i==n||j==m) break;
s1=0; s2=0;
s1 += a[i++], s2+= b[j++];
}
else if (s1<s2) s1 += a[i++];
else s2 += b[j++];
}
printf("%d\n", tot);
return 0;
}
C. Zebras
题意
一个\(01\)串,将其拆分成若干个格式为\(0101...010\)的(开头结尾均为\(0\),中间交替),每个串中的\(01\)与原序列中的先后顺序相同。要求给出方案。
思路
两个\(set\)分别记录\(0\)的位置和\(1\)的位置,配合\(lower\_bound\)使用。
结束条件:
- \(0\)的\(set\)为空
- \(1\)的\(set\)为空
- \(1\)的\(set\)与前一次不发生变化
Code
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
#define maxn 400010
using namespace std;
char s[maxn];
set<int> st[2];
vector<int> v[maxn];
typedef long long LL;
int main() {
scanf("%s", s);
int len = strlen(s);
F(i, 0, len) {
if (s[i]=='0') st[0].insert(i);
else st[1].insert(i);
}
int cnt=-1;
int count=0, temp=-1;
while (true) {
if (st[1].size()==temp || !st[0].size() || !st[1].size()) {
if (st[1].size()) puts("-1");
else {
printf("%d\n", cnt+1+st[0].size());
F2(i, 0, cnt) {
printf("%d ", v[i].size());
for (auto x : v[i]) printf("%d ", x+1); puts("");
}
for (auto x : st[0]) printf("%d %d\n", 1, x+1);
}
break;
}
temp = st[1].size();
int cur=0, x=-1;
++cnt;
while (true) {
auto it = st[cur].lower_bound(x);
if (it == st[cur].end()) {
if (cur==0) {
st[1].insert(x);
v[cnt].pop_back();
}
break;
}
else {
v[cnt].push_back(*it);
x = *it;
st[cur].erase(it);
cur = !cur;
}
}
}
return 0;
}
D. A Leapfrog in the Array
题意
思路
找呀找呀找规律。
元素\(x\)跳\(k\)次的步长分别为\((2(n-x)+1)*(1,2,4,8,...\),
所以跳\(k\)次后的位置为\(2x-1-(2(n-x)+1)(2^{k+1}-1)=(2x-1-2n)*2^{k+1}+2n\),
所以\(P_{k+1}=(2x-1-2n)*2^{k+2}+2n\),
所以\(P_{k}=P_{k+1}/2+n\)
于是可以从当前位置一路往后推,推到下标为奇数为止。
Code
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long LL;
LL n; int q;
LL calc(LL x) {
if (x&1) return (x+1)>>1;
return calc(n+(x>>1));
}
int main() {
scanf("%I64d%d", &n,&q);
while (q--) {
LL x, ans;
scanf("%I64d", &x);
printf("%I64d\n", calc(x));
}
return 0;
}
E. Data Center Maintenance
具体见 http://www.cnblogs.com/kkkkahlua/p/8541916.html
反思
开学打了两场均一塌糊涂。
挺多原因吧,包括各种外界环境以及干扰啥的,心态也浮躁,也可能是这几天睡得都比较晚,归根到底还是菜。
就今天这场而言,
\(A,B\)写得都很慢,
\(C\)题一开始因为输出格式错误在\(pretest\ 1\)都挂了好几次,后来\(T\)了一次,然后想到用\(set\)还挺高兴的,结果不明原因的一直\(RE\),本地一直跑也跑不出问题,就只能放弃了。
比赛结束麻烦同学跑才发现st[cur].erase(it); x = *it; // 别人家的IDE
我也是很强了,\(erase\)完还去取它的值。
\(C\)题没辙了就去看\(D\)题,还挺快就找到了初步的规律,也就是找到了\(P_k\),然而没有化简,于是就愣没看出来能怎么用。明明是这么棒的递推啊。
心浮气躁。可以的。
暂时的状态看起来不太能打了...。
等稍微进入正轨吧。学习上要忙的事情也是很多啊。
有闲情的话可以打打virtual,然后等天时地利人和。
再菜也还是要努力地活下去呢。
晚安晚安。
Codeforces Round #469 Div. 2 A B C D E的更多相关文章
- Codeforces Round #469 (Div. 2)
Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...
- Codeforces Round #469 (Div. 1) 949C C. Data Center Maintenance (Div. 2 950E)
题 OvO http://codeforces.com/contest/949/problem/C codeforces 949C 950E 解 建图,记原图为 G1,缩点,记缩完点后的新图为G2 缩 ...
- Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...
- Codeforces Round #469 (Div. 2) F. Curfew
贪心 题目大意,有2个宿管分别从1和n开始检查房间,记录人数不为n的房间个数,然后锁住房间. 没有被锁的房间中的学生可以选择藏在床底,留在原地,或者转移(最远转移d个房间) 然后抄了网上大神的代码 ...
- Codeforces Round #469 (Div. 2) E. Data Center Maintenance
tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...
- Codeforces Round #469 Div. 2题解
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- 【个人训练】(ZOJ3983)Crusaders Quest
题意分析 和祖玛类似的那种玩法.不过是限定了九个字符,问最好情况下有几次三连碰. 暴力穷举即可.具体的做法是,先把所有"成块"的字符记录下来,然后一个一个删,再继续这样子递归做下去 ...
- 孤荷凌寒自学python第七十四天开始写Python的第一个爬虫4
孤荷凌寒自学python第七十四天开始写Python的第一个爬虫4 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 直接上代码.详细过程见文末屏幕录像 ...
- packstack安装ironic
KVM Centos7.3虚机 安装openstack Pike版本, 其它版本安装方法类似. packstack目前对NetworkManager 还不支持,我们修改下配置: systemctl d ...
- 【习题集锦】全国青少年NOIP培训教材 ISBN 978-7-305-04246-1
目录 第一章 回溯法 找路径问题 递归代码: procedure find(k:integer); {找第K步的可能性} begin if 到目的地 {表示一条路已找出} then begin 输出路 ...
- Python 3 学习笔记之——基础语法
1. a, b = a, a + b 先计算右边表达式,然后再同时赋值给左边. 2. 条件控制和循环语句 条件控制 if condition_1: statement_block_1 elif con ...
- Halcon17对硬件配置要求
Halcon17对硬件配置要求 Halcon17已经发布出来了,很多朋友一定想安装这款机器视觉软件来学习,我们今天给大家讲解下,Halcon17对硬件配置的要求: Halcon17 For Wind ...
- Daily Scrum02 12.04
第二轮迭代已经进行到了白热化阶段,大家在被编译搞的水深火热的同时依然没有忘记我们的具有颠覆性的团队项目.虽然第一轮迭代我们的成绩不错,但是一定要克服时间不充裕,任务互相冲突的困难,克服不可避免的舆论压 ...
- Sql Express数据备份和还原
参考文章:在SQL Server Express版本中没有代理功能如何自动备份数据库 首先用以下脚本,生成可以自动备份数据库的存储过程: USE [master] GO SET ANSI_NULLS ...
- Qt5.6关联VS2013,配置VAssistX
1. 安装Qt qt-creator-opensource-windows-x86-4.2.0.exe 2. 安装Qt VS插件 qt-vs-addin-1.2.5.exe 3. 配置ASSISTX ...
- Hangman游戏源代码 --- python实现
#hangman.py from PythonCard import model,dialog import random def find_letters(letter,a_string): loc ...