Problem A:

题目大意:给你一个由0,1组成的字符串,如果有相邻的0和1要消去,问你最后还剩几个字符。

写的时候不想看题意直接看样例,结果我以为是1在前0在后才行,交上去错了。。后来仔细

看了看,哎。以后不能自以为是啊。

#include<bits/stdc++.h>
using namespace std;
const int N=*1e5+;
char s[N];
bool vis[N];
int main()
{
int n;
scanf("%d%s",&n,s);
int cnt=n;
int cnt1=,cnt0=;
for(int i=;i<n;i++)
{
if(s[i]=='') cnt0++;
else cnt1++;
}
printf("%d\n",max(cnt0-cnt1,cnt1-cnt0));
}

Problem B:

题目大意:给你n个一排的齿轮,每个齿轮有编号(0->n-1)的锯齿,问你能不能转动第一个轮子,

使其向上的锯齿依次为,0,1,2,3...n-1。水题,你就把第一个齿轮转到0的次数记录下来,第偶数

个加上,奇数个减去,判断一下。

#include<bits/stdc++.h>
using namespace std;
const int N=;
int a[N];
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++) scanf("%d",&a[i]);
int cnt=n-a[];
//printf("%d\n",cnt);
for(int i=;i<n;i++)
{
if(i%)
{
if((a[i]-cnt+n)%n!=i)
{
puts("No");
return ;
}
}
else
{
if((a[i]+cnt+n)%n!=i)
{
puts("No");
return ;
}
}
}
puts("Yes");
return ;
}

Problem C:

题目大意:给你n个编号1->n的杯子,编号代表了它们的大小,只有大的能套在小的上,现在

给你这些杯子现在的情况,让你把他变成1<-2<-3<-4....<-n这种形式需要操作几次。简单模拟

一下就好了。

#include<bits/stdc++.h>
using namespace std;
int n,k,ans,st;
int pre[];
void Find(int x)
{
if(pre[x]!=x)
{
Find(pre[x]);
ans++;
pre[x]=x;
}
}
void judge(int now,int p)
{
if(now==p+ || p==-)
{
st=now;
judge(pre[now],now);
}
}
int main()
{
cin>>n>>k;
for(int i=;i<=n;i++) pre[i]=i;
for(int i=;i<=k;i++)
{
int m;
scanf("%d",&m);
int p=-;
while(m--)
{
int g;
scanf("%d",&g);
if(p!=-)
{
pre[p]=g;
}
p=g;
}
}
ans=;
st=;
judge(,-);
Find(st);
for(int i=st+;i<=n;i++)
{
Find(i);
pre[i-]=i;
ans++;
}
cout<<ans<<endl;
return ;
}

Problem D:

题目大意:有n个排成以行的小道他们的范围分别是(l[i]->r[i])且l[i+1]>r[i],现在有m个长度为b[i]的桥

两个岛能加上长度为a的桥当且仅当 r[i+1]-l[i]>=a>=l[i+1]-r[i]。问你能不能完成这个工作。

这个题很显然,可以转换成这个问题:有n-1个区间,m个数,每个数最多只能用一次,第i个数只

要能被第j个区间包含,那么这个数就可以放入这个区间内。求出,当所有区间里都恰有一个数时的情况。

我写的时候一直在想固定最大范围和最小范围来贪心,用桥去满足他们,这种方法是不对的。

思路:我们可以将区间按按l排序,桥按长度排序,然后将当前满足 r>=a>=l 的区间都加到优先队列

里面,每次取出r最小的区间,这个桥就搭在这个区间上,为什么呢,因为对于优先队列里面的区间

来说,当前及以后的桥都满足,len[i]>=l 所以可以不用考虑区间的l,这样我们显然就可以贪心地取

r小的区间。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=*1e5+;
struct node
{
ll mx,mn;
int id;
bool operator <(const node&t) const
{
return mx>t.mx;
}
}w[N];
bool cmp(node a,node b)
{
return a.mn<b.mn;
}
struct num
{
ll v;
int id;
bool operator <(const num &t)const
{
return v<t.v;
}
}a[N];
ll ans[N];
int n,m;
int main()
{
cin>>n>>m;
ll pl=-,pr=-;
for(int i=;i<n;i++)
{
ll l,r;
scanf("%I64d%I64d",&l,&r);
if(pl!=-)
{
//printf("%d**\n",i);
w[i].mx=r-pl;
w[i].mn=l-pr;
w[i].id=i;
}
pl=l,pr=r;
}
for(int i=;i<=m;i++)
{
scanf("%I64d",&a[i].v);
a[i].id=i;
}
sort(a+,a++m);
sort(w+,w+n,cmp);
//for(int i=1;i<=m;i++) printf("%I64d ",a[i].v);
//puts("");
//for(int i=1;i<n;i++) printf("[%I64d,%I64d] ",w[i].mn,w[i].mx);
priority_queue<node> Q;
int cnt=;
for(int i=,j=;i<=m;i++)
{
while(w[j].mn<=a[i].v && a[i].v<=w[j].mx && j<n)
{
Q.push(w[j]);
j++;
}
if(Q.empty()) continue;
node now=Q.top();Q.pop();
if(a[i].v>now.mx)
{
puts("No");
return ;
}
ans[now.id]=a[i].id;
cnt++;
}
//printf("%d\n",cnt);
if(cnt<n-)
{
puts("No");
return ;
}
puts("Yes");
for(int i=;i<n;i++) printf("%I64d%c",ans[i],i==n-?'\n' : ' ');
return ;
}

problem E:

题意:

有一块n*n大小的巧克力,n<=1e9。现在进行操作,每次都从反对角线上选择一点,然后往上或往左一直吃,

每当到达巧克力边缘或者下一块已经被吃了,则停止。问你每次操作能吃到几块巧克力。

思维题,感觉挺难想到了,还是我太菜了。。

思路:我们考虑从j列往上吃巧克力,吃掉的个数受什么影响呢,肯定不受<j的列印象,对它有直接影响的就

他右边第一个有操作的点,如果这个点的操作时向左吃,则从j列向上吃只能吃到有操作点的那一行,如果右边

第一个有操作的点是向上吃,则j列吃的和它一样。

#include<bits/stdc++.h>
using namespace std;
map<int,int> u,l;
int n,q;
int main()
{
cin>>n>>q;
while(q--)
{
int x,y;
char s[];
scanf("%d%d%s",&x,&y,s);
map<int,int>::iterator p;
if(s[]=='U')
{
int ans=;
p=u.lower_bound(x);
if(u.count(x))
{
puts("");
continue;
}
if(p==u.end()) ans=y;
else ans=y-(p->second);
printf("%d\n",ans);
l[y]=x;
u[x]=y-ans;
}
else
{
int ans=;
p=l.lower_bound(y);
if(l.count(y))
{
puts("");
continue;
}
if(p==l.end()) ans=x;
else ans=x-(p->second);
printf("%d\n",ans);
u[x]=y;
l[y]=x-ans;
}
}
return ;
}

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

  1. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  2. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  3. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  4. Codeforces Round #310 (Div. 1) C. Case of Chocolate set

    C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...

  5. Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题

    B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  6. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  7. Codeforces Round #310 (Div. 1) B. Case of Fugitive set

    B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...

  8. Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. Codeforces Round #310 (Div. 2)--B

    http://codeforces.com/problemset/problem/556/B 题意:给定n个数字且都小于n,然后每次循环第2k+1个数字+1,第2k个数字减一,k=0,1,2...n/ ...

  10. Codeforces Round #310 (Div. 2)--A(简单题)

    http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少 ...

随机推荐

  1. 八、uboot 代码流程分析---board_init_f

    接着上一节,板子开始做前期初始化工作. 8.1 board_init_f Board_f.c (common) /* 板子初次初始化.boot_flags = 0 */ void board_init ...

  2. OpenCV中MAT中数据类型的设置(转)

    前言 opencv中很多数据结构为了达到內存使用的最优化,通常都会用它最小上限的空间来分配变量,有的数据结构也会因为图像文件格式的关系而给予适当的变量,因此需要知道它们声明的空间大小来配置适当的变量. ...

  3. [USACO]地震 (二分答案+最优比率生成树详解)

    题面:[USACO 2001 OPEN]地震 题目描述: 一场地震把约翰家的牧场摧毁了, 坚强的约翰决心重建家园. 约翰已经重建了N个牧场,现在他希望能修建一些道路把它们连接起来.研究地形之后,约翰发 ...

  4. Picasso的使用

    相信做Android开发的对Square公司一定不会陌生,大名鼎鼎的网络请求框架Retrofit就来源于它,今天学习的是该公司出品的图片加载框架Picasso. 项目地址 https://github ...

  5. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165320

    下载源 Kali官网 下载安装过程是按照链接博客的操作完成的 虚拟机VMware安装Kali 安装成功截图 安装VM Tools 首先进入虚拟机,默认用户名为root,密码为安装过程中自己设置的. 在 ...

  6. Linux磁盘分区、挂载

    ⒈Linux下磁盘说明 1)Linux硬盘分IDE硬盘和SCSI硬盘,目前基本上是SCSI硬盘. 2)对于IDE硬盘,使用“hdx~”标识符,“hd”代表IDE硬盘.   对于SCSI硬盘,使用“sd ...

  7. 再谈:自定义结构体的对齐问题之__attribute__ ((packed))方法【转】

    转自:https://blog.csdn.net/ipromiseu/article/details/5955295 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.c ...

  8. 利用grub从ubuntu找回windows启动项

    在 /boot/grub/grub.cfg 中添加: menuentry "Windows 10" --class windows --class os { insmod ntfs ...

  9. 使用ajax上传表单(带文件)

    在使用form表单的时候上传文件+表单,会使得页面跳转,而在某些时候不希望跳转,只变化页面中的局部信息 通过查找资料,可以使用FormData进行ajax操作. FormData介绍:XMLHttpR ...

  10. C#面向对象(封装)

    以上就是面向对象的封装和初始化: