Codeforces Round#310 div2
C题:这题说的是套娃,如果做题的时候知道是套娃,那就好理解多了
规则1:套娃A可以放到套娃B里面,当且仅当套娃B没有放在其他套娃里面
规则2:套娃A放在套娃B里面,且套娃B没有放在其他套娃里面,那么可以把A从B中拿出来
问我们最少要操作多少次,才能将套娃全部套起来,拆开和组装都算是一次操作
思路:找到序号为1的套娃的哪一组,然后统计该组有多少个套娃是连在1后面,且每次序号都是加1的,那么这些个套娃是不用拆开的。那么剩下的套娃都是要拆开的
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/* */
int a[ + ];
int main()
{ int n, k, m;
int ans;
int cnt;
while (scanf("%d%d", &n, &k) != EOF)
{
ans = cnt = ;
for (int i = ; i < k; ++i)
{
scanf("%d", &m);
bool flag = false;
for (int j = ; j < m; ++j)
{
scanf("%d", &a[j]);
if (a[j] == )
{
flag = true;
}
} if (flag)
{
cnt = ;
for (int j = ; j < m; ++j)
{
if (a[j] - == a[j - ])
cnt++;
else
break;
}
ans += m - cnt;
flag = false;
}
else
ans += m - ;
}
ans += n - cnt;
printf("%d\n", ans);
}
return ;
}
D题:当时的想法是把岛屿按距离下一个的岛屿的距离,从小到大排序, 并且将桥的长度也从小到大排序,然后进行贪心, 但是问题是
可能贪心的时候,选择了当前的桥A,但是桥B也时候自己(桥A排在桥B前面), 但是呢,到下一个岛屿的时候,桥B对它来说,太长了。
例子:三个岛屿,两座桥,按上面那样子贪心是不行的。
1 10
11 16
20 23
10 15
上面的贪心策略,没有考虑到的信息是岛屿自身的长度。仅考虑了岛屿与岛屿之间的距离
我们规定上界是:两个岛屿之间能建立的最长的桥, 下界是:最短的桥
我们可以将岛屿按照上界进行排序,然后选择桥的时候,找到第一个大于等于下界的桥即可。这样就不会发生上面所说的那种情况(因为上界是递增的)
还有一点就是STL的lower_bound()函数极端情况下,时间复杂度是O(n),会超时
可以将桥的长度存到set中,然后用set自带的lower_bound()函数, 时间复杂度是O(logn)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = << ;
/* */
const int N = + ;
struct Island
{
LL l, r, upper, lower, id;
bool operator<(const Island&rhs)const
{
return upper < rhs.upper;
}
}island[N];
set<pair<LL, int> > b;
int ans[N];
int main()
{
int n, m;
LL a;
scanf("%d%d", &n, &m);
for (int i = ; i < n; ++i)
{
scanf("%I64d%I64d", &island[i].l, &island[i].r);
}
for (int i = ; i < n - ; ++i)
{
island[i].id = i;
island[i].lower = island[i + ].l - island[i].r;
island[i].upper = island[i + ].r - island[i].l;
}
sort(island, island + n - );
for (int i = ; i < m; ++i)
{
scanf("%I64d", &a);
b.insert(make_pair(a, i));
}
for (int i = ; i < n - ; ++i)
{
set<pair<LL, int> >::iterator iter = b.lower_bound(make_pair(island[i].lower, ));
if (iter == b.end())
{
puts("No");
return ;
}
else
{
if (iter->first <= island[i].upper)
{
ans[island[i].id] = iter->second + ;
b.erase(iter);
}
else
{
puts("No");
return ;
}
}
}
puts("Yes");
printf("%d", ans[]);
for (int i = ; i < n - ; ++i)
printf(" %d", ans[i]);
puts("");
return ;
}
E题:
对于向上走的点,那么只有比自己大的x能影响到自己
对于向左走的点,那么只有比自己小的x能影响到自己
用set就行了。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/*
6 5
3 4 U
6 1 L
5 2 U
4 3 U
2 5 U 如果向上走,那么只有比自己大的x[i]向左走能影响到自己
如果向左走,那么只有比自己小的x[i]向上走能影响到自己
*/
const int N = + ;
set<pair<int,int> > s;
set<pair<int, int> >::iterator it;
int x[N], y[N];
int main()
{
int n, q;
char d[];
scanf("%d%d", &n, &q);
s.insert(make_pair(, q+));
s.insert(make_pair(n + , q+));
x[] = y[] = ;
for (int i = ; i <= q; ++i)
{
scanf("%d%d%s", &x[i], &y[i], d);
if (d[] == 'U')
{
it = s.lower_bound(make_pair(x[i], -));
}
else
{
it = s.upper_bound(make_pair(x[i], q+));
//it-- , 找到比自己小的x
it--;
}
if (it->first == x[i])
{
printf("0\n");
continue;
}
s.insert(make_pair(x[i], i));
if (d[] == 'U')
{
printf("%d\n", y[i] - y[it->second]);
//影响是可以传递的
y[i] = y[it->second];
}
else
{
printf("%d\n", x[i] - x[it->second]);
x[i] = x[it->second];
}
}
return ;
}
目标:①div2做4题 ②一次AC,手速快,题意看清
Codeforces Round#310 div2的更多相关文章
- Codeforces Round #539 div2
		Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ... 
- 【前行】◇第3站◇ Codeforces Round #512 Div2
		[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ... 
- 贪心/思维题 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#320 Div2 解题报告
		Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ... 
- Codeforces Round #564(div2)
		Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ... 
- Codeforces Round #361 div2
		ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ... 
- Codeforces Round #626 Div2 D,E
		比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ... 
随机推荐
- ExtJs4 笔记(12) Ext.toolbar.Toolbar 工具栏、Ext.toolbar.Paging 分页栏、Ext.ux.statusbar.StatusBar 状态栏
			本篇讲解三个工具栏控件.其中Ext.toolbar.Toolbar可以用来放置一些工具类操控按钮和菜单,Ext.toolbar.Paging专门用来控制数据集的分页展示,Ext.ux.statusba ... 
- Esper学习之四:Context
			上周末打球实在太累了,就没来得及更新,只是列了个提纲做做准备,发现Context还是有很多内容的.结果也花了不少时间才写完,所以这篇需要各位慢慢消化,并且最好多写几个例子加深理解. 如果有不了解Esp ... 
- 第十七篇:实例分析(1)--初探WDDM驱动学习笔记(八)
			第四篇(VidPN)中提到过MIRROR驱动. 在进入本篇的实际内容前, 带着好奇心, 想请教CSDN中的显卡驱动方面的大虾, 怎样才干把这个驱动玩起来, 这个驱动的作用是什么,等等, 敬请不吝赐教. ... 
- Delphi默认窗体随想
			Delphi中新建一个Form或者Frame时,它的字体都是西文习惯,这样就有可能造成在其他机器上由于字体的原因,窗体十分不美观.怎样才能为Delphi设置一个默认窗体,让它的字体Font符合中国习惯 ... 
- EndNote是一款着名的参考文献管理软件
			EndNote是一款着名的参考文献管理软件,我们可以通过该软件创建个人参考文献库,此外对公司DCC.法务和专 利部门十分的有用,甚至对我们写SOP 也有些帮忙,并且该软件可以在其中加入文本.图像.表格 ... 
- Java Web Services (1) - 第1章 Web服务快速入门
			SCRIPTS_DIR=/Users/liuzhaofu/opus-dev/product/tools/devPRODUCT_DIR=/Users/liuzhaofu/opus-dev/product ... 
- Linux vmstat命令详解
			vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.这个命令是我查看Linux/Unix最 ... 
- 使用AjaxFileUpload.js实现文件异步上�
			ajax是无法提交文件的,所以在上传图片并预览的时候,我们常常使用Ifame的方法实现看似异步的效果.可是这样总不是非常方便的,AjaxFilleUpload.js对上面的方法进行了一个包装,使得我们 ... 
- Java中double变量精确到小数点后几(2)位
			import java.math.BigDecimal; import java.text.NumberFormat; public class Java中double类型的数据精确到小数点后两位 { ... 
- [置顶] iframe使用总结(实战)
			说在前面的话,iframe是可以做很多事情的. 例如: a>通过iframe实现跨域; b>使用iframe解决IE6下select遮挡不住的问题 c>通过iframe解决Ajax的 ... 
