Codeforces Round #310 (Div. 2)简洁题解
A:原来是大水题,我还想去优化。。
结果是abs(num('0')-num('1'));
num表示一个符号的个数;
B:暴力模拟即可,每次判断是否能构造出答案。
C:俄罗斯套娃,套套套,捉鸡的E文。
抛开乱七八糟的题意;
思路就是除了1连续的不拆开,其他都拆,所以乱写就好了。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include<string>
using namespace std;
#define N 222222
typedef long long ll; int a[N]; int main()
{
int n,k;
cin>>n>>k;
int ans=; for (int i=;i<=k;i++)
{
int m;
cin>>m;
for (int j=;j<=m;j++) cin>>a[j];
ans+=m-; int pos=n+;
for (int j=;j<=m;j++)
if (a[j]==) pos=j; for (int j=pos+;j<=m;j++)
if (a[j]-==j-pos)
ans-=; } cout<<ans+n-;
return ;
}
D:我们先求出两座相邻的岛需要桥的范围是[x,y];即 node a.x,a.y;
思路关键词:贪心;
解析:先按y从小到大排序,相同,x大的在前。
即:
int cmp(node a,node b)
{
if (a.y==b.y) return a.x>b.x;
return a.y<b.y;
}
然后对于每个桥我们都丢到set 中,可能有相同元素,加一维序号; 对于node 我们在set中 找大于node a.x 最前的 然后从set中删除。 为何这么做:
因为排好序后,最前的优先级一定最高,想想。
三种情况:
【 】 ...1
【 】 ...2
【 】...3
满足1的一定满足2,满足2的不一定满足1,同理2满足,也满足3,满足3,不一定满足2
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include<string>
using namespace std;
#define N 222222
typedef long long ll;
#define mp make_pair struct node
{
ll x,y;
int flag;
}b[N];
int n,m; ll l[N],r[N]; set<pair<ll,int> >S;
set<pair<ll,int> >::iterator it; struct node2
{
ll x;
int idx;
}a[N]; int cmp(node a,node b)
{
if (a.y==b.y) return a.x>b.x;
return a.y<b.y;
} int ans[N]; int main()
{ scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
scanf("%I64d%I64d",&l[i],&r[i]); for (int i=;i<=m;i++) {
scanf("%I64d",&a[i].x);
S.insert(mp(a[i].x,i));
} for (int i=;i<n;i++)
b[i].x=l[i+]-r[i],b[i].y=r[i+]-l[i],b[i].flag=i; sort(b+,b+n,cmp); for (int i=;i<n;i++)
{ it=S.lower_bound(mp(b[i].x,));
if (it==S.end()||(it->first>b[i].y))
{
cout<<"No";
return ;
} ans[b[i].flag]=it->second; S.erase(it);
} cout<<"Yes"<<endl;
for (int i=;i<n;i++) cout<<ans[i]<<" ";
return ;
}
E :不会
Codeforces Round #310 (Div. 2)简洁题解的更多相关文章
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
随机推荐
- objdump命令
0x00 objdump命令是Linux下的反汇编目标文件或者可执行文件的命令 0x01 objdump -f 显示test的文件头信息 $ objdump -f levellevel: file ...
- java上传、下载、删除ftp文件
一共三个类,一个工具类Ftputil.,一个实体类Kmconfig.一个测试类Test 下载地址:http://download.csdn.net/detail/myfmyfmyfmyf/669710 ...
- VUE2中axios的使用方法
一,安装 npm install axios 二,在http.js中引入 import axios from 'axios'; 三,定义http request 拦截器,添加数据请求公用信息 axio ...
- Vue开发微信公众号默认背景为灰色
最近公司有一个项目,使用Vue开发微信公众号,开发过程遇到一个问题,即设计图的整体背景是白色的,但是公众号里默认的背景是浅灰色,如果某个页面高度没能占满一屏,就会露出浅灰色的默认背景,会显得很不协调. ...
- 关于HTML设置访问密码。
如果你要设置访问密码恐怕要使用sublime_text了 废话不多,开始!!! 先把这些东西加上: <html> <script> 然后开始写代码: 先辨别密码登录正确的情况: ...
- 【dp 贪心】bzoj4391: [Usaco2015 dec]High Card Low Card
巧妙的贪心 Description Bessie the cow is a huge fan of card games, which is quite surprising, given her l ...
- 【Java_多线程并发编程】JUC原子类——原子类中的volatile变量和CAS函数
JUC中的原子类是依靠volatile变量和Unsafe类中的CAS函数实现的. 1. volatile变量的特性 内存可见性(当一个线程修改volatile变量的值后,另一个线程就可以实时看到此变量 ...
- ps命令查看子进程
[root@centos7 log]# ps -f -e -o pid,ppid,pgid,comm PID PPID PGID COMMAND 5070 5068 5070 bash 7169 50 ...
- perl学习 之:my local our
范围声明 和全局声明类似,词法范围声明也是在编译时起作用的.和全局声明不同的是,词法范围声明的作用范围是从声明开始到闭合范围的最里层(块,文件,或者 eval--以先到者为准).这也是为什么我们称它为 ...
- 元组-tuple
Python内置的元组数据类型:tuple tuple和list非常类似,但tuple一旦初始化就不能修改,因此它没有append(),insert()这样的方法 当定义一个tuple时,tuple的 ...