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

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

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

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

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

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

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

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

  5. Codeforces Round #469 Div. 2 A B C D E

    A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...

  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. 用贪心算法近似求解 Loading Balance 问题(作业调度的负载均衡)

    一,Loading Balance 问题描述:有 m 台相同的机器及 n 个作业,其中 m={M(1),M(2),……M(m)}.n = {J(1),J(2),……J(n)}.每个作业都有一个处理时间 ...

  2. WebStrom直接启动VUE项目

    点Run即可启动

  3. Newtonsoft.Json 两个Attribute含义

    1.[JsonIgnore] 看名字就知道了,通过这个Attribute可以忽略序列化某个实体类字段 2.[JsonProperty("Font")] 设置序列化到json中的实际 ...

  4. python自带的调试器

    python是自带调试器的. 比如你写了一个python程序,名叫test.py. 你想调试一下这个程序,你可以执行 python -m pdb test.py,就会进入test.py的调试. 想查看 ...

  5. Oracle——存储过程的使用

    为什么使用存储过程? 存储过程只在创造时进行编译,以后每次执行存储过程都不需再重新编译,而一般SQL语句每执行一次就编译一次,所以使用存储过程可提高数据库执行速度. 存储过程的定义: 存储过程(Sto ...

  6. Postfix 邮件服务 - 基础服务

    环境 centos 6.5 x64 测试 IP:172.16.2.18 1.关闭selinux # cat /etc/selinux/config SELINUX=disabled 2.配置 ipta ...

  7. QPushButton按钮

    需要 from PyQt5.QtWidgets import QPushButton继承 QAbstractButton 创建按钮控件:QPushButton() 创建一个无父控件的按钮控件QPush ...

  8. GET和POST有什么区别?及为什么网上多数答案都是错的(转载)

    这仅仅是我认为比较好的关于get和post区别的解答,然后把作者的一些文字踢除留下比较干的部分. 作者:南柯之石链接:http://www.cnblogs.com/nankezhishi/archiv ...

  9. mysql案例-sysbench安装测试

    一 地址 githup地址https://github.com/akopytov/sysbench二 版本 sysbench 1.0.15 curl -s https://packagecloud.i ...

  10. Shiro会话管理器与验证码实现(十四)

    和shiro整合后,使用shiro的session管理,shiro提供sessionDao操作 会话数据. 配置sessionManager