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 题意: 输入 ...
随机推荐
- Bootstrap响应式布局(1)
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 通过工厂模式批量创建对象后调用其中方法 出现XXXis not a function()问题原因
//通过工厂模式批量创建 function Computer(color,weight,logo){ var obj=new Object(); obj.color=c ...
- 如何把握好 transition 和 animation 的时序,创作描边按钮特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/mKdzZM 可交互视频教 ...
- $monitor用法
1.$monitor 进程同一时间有且仅有一个,若多次调用$monitor,新进程会代替以前的monitor进程. 2.$fmonitor可以同时存在任意个. 3.一般不用$monitor系统函数. ...
- 我的Python分析成长之路11
数据预处理 如何对数据进行预处理,提高数据质量,是数据分析中重要的问题. 1.数据合并 堆叠合并数据,堆叠就是简单地把两个表拼在一起,也被称为轴向链接,绑定或连接.依照轴的方向,数据堆叠可分为横向堆叠 ...
- ACM训练联盟周赛 Teemo's formula
Teemo has a formula and he want to calculate it quickly. The formula is . As the result may be very ...
- 一个线程中lock用法的经典实例
/* 该实例是一个线程中lock用法的经典实例,使得到的balance不会为负数 同时初始化十个线程,启动十个,但由于加锁,能够启动调用WithDraw方法的可能只能是其中几个 作者:http://h ...
- 咕咕咕,skkyk的博客生活从此开始了
2019-5-9 咕咕咕,skkyk的博客生活从此开始了 我是划水时长两个半小时的个人OIer skkyk,我喜欢打表,暴零,骗分,瞎搞(律师函警告); 2019-6-14 中考结束的第二天 我们苦逼 ...
- cookie小结(转)
原文地址:http://www.cnblogs.com/xianyulaodi/p/6476991.html#_label0 作者:咸鱼老弟 阅读目录 什么是cookie 官方定义:N ...
- 【LeetCode】Combination Sum II(组合总和 II)
这道题是LeetCode里的第40道题. 题目要求: 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. can ...