Codeforces Round #469 (Div. 2)
Codeforces Round #469 (Div. 2)
难得的下午场,又掉分了。。。。
Problem A: 怎么暴力怎么写。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; int n; int l,r,m;
int main()
{
read(l); read(r); read(m);
int ret=min(l,r);
int ans=;
ans+=ret*;
l-=ret;
r-=ret;
ret=min(l,m);
ans+=ret*;
l-=ret;
m-=ret;
ret=min(r,m);
ans+=*ret;
r-=ret;
m-=ret;
if(m&) m--;
printf("%d\n",ans+m);
return ;
}
/*
*/
Problem B:
题目大意:把一段信息分别拆成 A里的n段和 B里的m段,A和B都重新组合一下,最多有多少个信息片段相同。
思路:刚开始以为拆了之后是无序的,发现不会,重读了一下题,原来就是相邻的。。。。 处理一下前缀和,类似于
two point 搞一搞就好啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; int n,m;
ll a[N],b[N],sum1[N],sum2[N];
int main()
{
read(n); read(m);
for(int i=;i<=n;i++)
lread(a[i]);
for(int i=;i<=m;i++)
lread(b[i]); for(int i=;i<=n;i++)
sum1[i]=sum1[i-]+a[i];
for(int i=;i<=m;i++)
sum2[i]=sum2[i-]+b[i]; int p1=,p2=,ans=;
while(p1<=n && p2<=m)
{ while(sum1[p1]!=sum2[p2])
{
while(sum1[p1]<sum2[p2])
p1++; while(sum1[p1]>sum2[p2])
p2++; }
ans++;
p1++;
p2++;
}
printf("%d\n",ans);
return ;
}
/*
*/
Problem C:
题意:给你一个0,1组成的串,要求你按时间顺序任意组合成若干个串,要求每个串首尾都是0,且0和1不相邻。
思路:想了5分钟就会写了,从前往后处理,如果当前是0,且以前的串里最后一位没有1的,那么新开一个串,
否则接在以前那个串的后边,如果当前的是0,且以前的串里最后一位没有0的,输出-1,否则接在以前那个串
的后边,最后判断一下所有串的首尾是不是都是0。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; char s[N];
int cnt[N],tot,n;
vector<int> ans[N];
vector<int> num0,num1;
int main()
{
sread(s+);
n=strlen(s+);
for(int i=;i<=n;i++)
{
if(s[i]=='')
{
if(!num1.size())
{
ans[tot].push_back(i);
num0.push_back(tot);
tot++;
}
else
{
int id=num1[num1.size()-];
num1.pop_back();
ans[id].push_back(i);
num0.push_back(id);
}
}
else
{
if(!num0.size())
{
puts("-1");
return ;
}
else
{
int id=num0[num0.size()-];
num0.pop_back();
ans[id].push_back(i);
num1.push_back(id);
}
}
}
if(num1.size())
{
puts("-1");
return ;
}
printf("%d\n",tot);
for(int i=;i<tot;i++)
{
printf("%d ",ans[i].size());
for(int j:ans[i])
printf("%d ",j);
puts("");
}
return ;
}
/*
*/
Problem D:
题意:有n个数,数i在 2*i-1的位置,每次操作将最后一个元素,放到与其最近的空位置,知道1-n位置被填满。
思路:刚开始想找规律,找了半天没找到,后来发现前n个位置里边如果本来就有元素,那么这个元素一定是不会
变的,原来空着的地方全部都是大于n位置上的元素跳过来的,比如说第一个空位上最后的元素肯定是从位置在n+1
上的元素跳过来的,如果n+1还是空位则递归处理,否则,这个元素就是第一个空位的元素。
最后写的太慌了,调了半天没有A掉,赛后马上就A了,气死了。。。。。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; ll n,q,cnt=;
ll dfs(ll x,ll l,ll r)
{
if(x&)
return x;
if(l&)
{
ll cnt=(x-l)/+;
ll num=(r+)/-(l+)/+;
return dfs(l+num+cnt-,l+num,r);
}
else
{
ll cnt=(x-l)/+;
ll num=(r+)/-(l+)/+;
return dfs(l+num+cnt-,l+num,r);
}
}
int main()
{
lread(n); lread(q);
for(int i=;i<=q;i++)
{
ll x; lread(x);
ll ans=dfs(x,,*n-);
printf("%lld\n",(ans+)/);
}
return ;
}
/*
*/
Problem E:
题意:这个题意我真的讲不来。。。。。但是赛后补的时候感觉这个题比D简单。。
思路:对于c1,c2两个信息中心来说来说,如果t[c1] 是 t[c2] 前面一个时间,那么c1向c2建一条边,表明c1动了,c2必须动,
如果t[c2] 是 t[c1]前面一个时间,那么c2向c1建一条边,表明c2动了,c1必须动。 直接跑一个强连通分量,缩点之后变成一个
拓扑图,对于每个强连通分量来说,只有没有出度的才有机会成为答案,那么在没有出度的里面找最小值就好啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=3e6+;
const int M=; int n,m,h,dindex,all,cnt,t[N],dfn[N],low[N],st[N],id[N],dg[N];
bool inst[N];
vector<int> edge[N],ans[N]; void tarjan(int v)
{
dindex++;
dfn[v]=low[v]=dindex;
st[all++]=v; inst[v]=true;
for(int nx:edge[v])
{
if(!dfn[nx])
{
tarjan(nx);
low[v]=min(low[v],low[nx]);
}
else if(inst[nx]) low[v]=min(low[v],low[nx]);
}
if(dfn[v]==low[v])
{
cnt++;
while()
{
int cur=st[--all];
inst[cur]=false;
id[cur]=cnt;
ans[cnt].push_back(cur);
if(cur==v) break;
}
}
} int main()
{
read(n); read(m); read(h);
for(int i=;i<=n;i++)
read(t[i]);
for(int i=;i<=m;i++)
{
int c1,c2;
read(c1); read(c2);
if((t[c1]+)%h==t[c2])
edge[c1].push_back(c2);
if((t[c2]+)%h==t[c1])
edge[c2].push_back(c1);
} for(int i=;i<=n;i++)
if(!dfn[i])
tarjan(i); for(int i=;i<=n;i++)
for(int j:edge[i])
if(id[i]!=id[j])
dg[id[i]]++; int ret=inf,pos;
for(int i=;i<=cnt;i++)
if(dg[i]== && ans[i].size()<ret)
ret=ans[i].size(),pos=i; printf("%d\n",ret);
for(int i:ans[pos])
printf("%d ",i);
puts("");
return ;
}
/*
*/
Codeforces Round #469 (Div. 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 缩 ...
- 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 B C D E
A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...
- 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 ...
随机推荐
- npm webpack工具 (监听压缩等)
压缩.监听变动自动打包,:开发后,js编译压缩及样式去空格等 $ webpack --config XXX.js //url使用另一份配置文件(比如webpack.config2.js)来打包 $ w ...
- scapy的安装
我是安装了sulley,这里安装了pcapy的模块. https://github.com/zlorb/scapy ----按照此链接的步骤安装 但是在安装pycrypto模块出现了错误. 这里通 ...
- mvc小技巧
1.从Controller后台赋值的html标签显示在前台不起作用的问题?比如后台:ViewData["Message"]="<span style=\" ...
- Modelsim SE 安装
FPGA开发过程中,代码编写完成后,往往是需要通过第三方仿真工具去验证设计功能的正确性.本章介绍最常用的仿真工具--Modelsim SE的安装过程. 1.1.1.Modelsim SE安装 本节主要 ...
- Java探针-Java Agent技术-阿里面试题
Java探针参考:Java探针技术在应用安全领域的新突破 最近面试阿里,面试官先是问我类加载的流程,然后问了个问题,能否在加载类的时候,对字节码进行修改 我懵逼了,答曰不知道,面试官说可以的,使用Ja ...
- 【转】Python之函数进阶
[转]Python之函数进阶 本节内容 上一篇中介绍了Python中函数的定义.函数的调用.函数的参数以及变量的作用域等内容,现在来说下函数的一些高级特性: 递归函数 嵌套函数与闭包 匿名函数 高阶函 ...
- vsftpd控制用户禁止访问上级目录 只能访问自己目录
涉及文件: vsftpd.conf chroot_list_file=/etc/vsftpd.chroot_list 如果设置为 chroot_local_user=YES chroot_list_e ...
- malloc()函数(Linux程序员手册)及函数的正确使用【转】
转自:https://blog.csdn.net/david_xtd/article/details/7311204 名称 malloc,free,calloc,realloc--分配和释放动态内存 ...
- pl sql 存储过程 执行sql 锁死状态
背景 这是在一个不知如何表达的项目中,我在这个项目中做的就是不知如何表达的事情.只是想着技术,到是通过这个项目把存储过程基本能用的都用了,oracle开发的技术我感觉基本都全活了.别人没搞定的我搞定了 ...
- 非root用户执行java进程报错:fork: retry:资源暂时不可用
vim /etc/security/limits.conf # End of file * soft nproc 65535 * hard ...