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 题意: 输入 ...
随机推荐
- https 调用验证失败 peer not authenticated
https 调用验证失败 peer not authenticated 报错日志: Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer ...
- history.pushState 实现浏览器页面不刷新修改url链接
最近遇到了在不刷新页面的情况下修改浏览器url链接的需求,遂求助于万能的度娘,最终通过history.pushState()完美解决问题.现在将我理解的一些内容分享一下,不对的地方欢迎大家指出. 在使 ...
- codevs 数字三角形集结
添在前面的一句话:初学DP,若有错误,请指出,不能误人子弟,欢迎大家提出意见.水平不高,博客写的比较粗糙,代码也挺丑,请见谅. 最原始的数字三角形: 1220 数字三角形 时间限制: 1 s 空间 ...
- 【动态规划】loj#2485. 「CEOI2017」Chase
有意思的可做dp题:细节有点多,值得多想想 题目描述 在逃亡者的面前有一个迷宫,这个迷宫由 nnn 个房间和 n−1n-1n−1 条双向走廊构成,每条走廊会链接不同的两个房间,所有的房间都可以通过走廊 ...
- Python基础:列表(list)和元组(tuple)
学一门语言,可以用对比其他语言方法加深对这门语言特点的理解. 一.定义:列表和元组,都是一个可以放置任意数据类型的有序集合. mutable的列表:动态的,可以改变元素 immutable的元组:静态 ...
- DRF框架中的演变View
import json from django.db import DatabaseError from django.http import HttpResponse from django.htt ...
- HAL——学习SysTick
开始: 1.嵌套向量中断寄存器 (NVIC): 嵌套向量中断控制器 (NVIC) 和处理器内核接口紧密配合,可以实现低延迟的中断处理和晚到中断的高效处理.包括内核异常在内的所有中断均通过 NVIC 进 ...
- 几条sql语句(exists)
通常exists后的子查询是需要和外面的表建立关联关系的,如 select count(*) from a where exists (select 'x' from b where a.id = b ...
- 使用 RMAN 同步数据库
使用 RMAN同步数据库 使用 RMAN 同步数据库 一.概述 二 操作步骤 (一).把生产库置为归档模式 (二).启动rman做数据库0级备份 (三).修改生产库数据库到未归档 (四).拷贝备份集到 ...
- windows下在指定目录下打开命令行
直接用cd的话比较麻烦,可以先进入制定目录后,按住shift键,鼠标右键可以选择“在此处打开命令窗口”