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 题意: 输入 ...
随机推荐
- numpy中tile函数
tile函数位于python模块numpy.lib.shape_base中,他的功能是重复某个数组. 函数的形式是tile(A,reps) 函数参数说明中提到A和reps都是array_like的,什 ...
- struts1标签库
Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML标签 : 用来创建能够和Struts 框架和其他相应的HTML 标签交互的HTML 输入表单 ...
- 【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 ...
- Spring Boot + Mybatis + Druid 动态切换多数据源
在大型应用程序中,配置主从数据库并使用读写分离是常见的设计模式. 在Spring应用程序中,要实现读写分离,最好不要对现有代码进行改动,而是在底层透明地支持. 这样,就需要我们再一个项目中,配置两个, ...
- Android Studio问题记录
1>Android Studio中module是什么,? 答:Android Studio是基于intellij,跟eclipse不太一样.对应关系如下: intellij的project -- ...
- 简易的mysql性能查询脚本
#!/bin/bash mysqladmin -P3306 -uroot -p -h127. -r -i ext |\ awk -F"|" \ "BEGIN{ count ...
- 设置 TabBarItemt图片颜色
UIImage *discussSelectedImage = [UIImage imageNamed:@"discuss_selected"];//设置图片不渲染 discuss ...
- 【实验吧】Once More&&【笔记】 PHP 函数漏洞总结
<?php if (isset ($_GET['password'])) { if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) = ...
- 菜鸟的《Linux程序设计》学习—shell script
1. 认识shell script shell script是利用shell的功能缩写的一个"程序",这个程序是使用纯文本文件,将一些shell的语法与命令(含外部命令)写在里面, ...
- UVa 11987 并查集 Almost Union-Find
原文戳这 与以往的并查集不同,这次需要一个删除操作.如果是叶子节点还好,直接修改父亲指针就好. 但是如果要是移动根节点,指向它的所有子节点也会跟着变化. 所以要增加一个永远不会被修改的虚拟根节点,这样 ...