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 题意: 输入 ...
随机推荐
- 使用gcc -g编译,gdb调试时仍然存在“no debug symbols found”的错误
今天为调试一段代码,使用gcc将程序用-g选项重新编译.但是使用gdb进行debug时,仍然出现“no debug symbols found”的错误.仔细检查了一下Makefile,原来后面定义的连 ...
- bootstrap 两端对齐的导航
您可以在屏幕宽度大于768px时,通过在分别使用.nav .nav-tabs或.nav .nav-pills的同时使用class.nav-justified,让标签式或胶囊式导航菜单与父元素等宽,在更 ...
- HTML5触摸事件
touchstart .touchmove .touchend 事件 touchstart事件:当手指触摸屏幕时触发,即使有一个手指放在屏幕上也会触发. touchmove事件:当手指在屏幕上滑动时触 ...
- windows显示文件扩展名
搜索打开windows的文件资源管理选项,如下去掉“隐藏已知文件类型的扩展名”即可 打开之后显示如下:
- curl学习笔记(以php为例)
一.demo,抓取百度页码代码: $url = 'https://www.baidu.com/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RE ...
- IE10无法识别setPrototypeOf属性问题
项目遇到一个需求,React16.6.0兼容IE10浏览器 首先在IE浏览器打开,IE11可以支持,打开控制台切换到IE10,页面白屏,控制台报错. 控制台报错 vue2.0 兼容ie9及其以上 Ma ...
- 条款52:写了placement new 也要写placement delete(write placement delete if you write placement new)
NOTE: 1.当你写一个placement operator new .请确定也要写出了对应的placement operator delete.如果没有这样做,你的程序可能发生隐晦而时断时续的内存 ...
- Python数据分析库之pandas,你该这么学!No.1
写这个系列背后的故事 咦,面试系列的把基础部分都写完啦,哈哈答,接下来要弄啥嘞~ pandas吧 外国人开发的 翻译成汉语叫 熊猫 厉害厉害,很接地气 一个基于numpy的库 干啥的? 做数据分析用的 ...
- UIBarButtonSystemItem 样式
使用时需要注意创建方式的区别: 01 typedef enum { 02 UIBarButtonSystemItemDone, 03 UIBarButtonSystemItemCanc ...
- LeetCode(202) Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defi ...