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\)使用。

结束条件:

  1. \(0\)的\(set\)为空
  2. \(1\)的\(set\)为空
  3. \(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的更多相关文章

  1. Codeforces Round #469 (Div. 2)

    Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...

  2. 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 缩 ...

  3. Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)

    C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...

  4. Codeforces Round #469 (Div. 2) F. Curfew

    贪心 题目大意,有2个宿管分别从1和n开始检查房间,记录人数不为n的房间个数,然后锁住房间. 没有被锁的房间中的学生可以选择藏在床底,留在原地,或者转移(最远转移d个房间)   然后抄了网上大神的代码 ...

  5. Codeforces Round #469 (Div. 2) E. Data Center Maintenance

    tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...

  6. Codeforces Round #469 Div. 2题解

    A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...

  7. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

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

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. 「Haskell 学习」一 环境与大致了解

    感谢<Real World Haskell>在网上的免费发布,可以白嫖学Haskell这个久闻大名的函数式编程语言了. 本文运行于openSUSE Tumbleweed下,运行相关命令时留 ...

  2. Ubuntu下使用Git_5

    还欠大家最后一篇Git的学习. Git的下一个内容,标签,标签是为了更方便的参考提交而给他表上通俗易懂的名称 Git可以使用两种标签,轻标签和注解标签,打上的标签是固定的,不能向分支那样可以移动位置, ...

  3. url解读

    我刚刚学习的时候,我抓到包不知道哪个是协议.哪个是是服务器地址.哪个是端口号...不知道有没有老铁遇到跟我一样的. 接口:http://172.168.12.0:8888/old/login.do 解 ...

  4. CentOS Linux release 7.5.1804下安装MySQL5.7.24

    1.环境查看: 2.卸载自带MariaDB数据库: 3.下载MySQL5.7.14安装包: 4.使用wget工具下载需要安装数据库的依赖包: 5.解压缩bundel包: 6.按照顺序进行安装: 7.数 ...

  5. liunx运维必备150个基础命令

    经过上次的面试,总结了一下的linux系统常用命令: 命令 功能说明 线上查询及帮助命令(2个) man 查看命令帮助,命令的词典,更复杂的还有info,但不常用. help 查看Linux内置命令的 ...

  6. docker基础-虚拟化与容器介绍

    正如所有关心docker技术的人所知道的那样,docker是以容器虚拟化为技术为基础的软件,因此在学习docker具体的内容之前,有必要讨论一下虚拟化和容器技术. 虚拟化技术: 在了解虚拟化技术时,各 ...

  7. 持久化ORM框架——Hibernate与mybatis

    最初SUN公司推出了JavaEE服务器端组件模型(EJB),但是由于EJB配置复杂,且适用范围较小,于是很快就被淘汰了.与EJB的失败伴随而来的是另外一个框架的应运而生.他就是至今也比较流行的Hibe ...

  8. spring笔记(一)

    1. 回顾 Struts与Hibernate可以做什么事? Struts, Mvc中控制层解决方案 可以进行请求数据自动封装.类型转换.文件上传.效验… Hibernate, 持久层的解决方案: 可以 ...

  9. 获取web服务器路径的方法 getResourceAsStream

    1.先获取 serlvetContext对象 2.调用getResourceAsStream  在方法里 "\"表示当前web的根目录  还要拼接上具体的文件路径 ServletC ...

  10. Augmenting Path Algorithm : 一般图最大匹配

    算法原理详见 http://www.csie.ntnu.edu.tw/~u91029/Matching.html orz 带花树很神奇,挖坑最大权匹配 #include <iostream> ...