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的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  4. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  5. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  6. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  7. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  8. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  9. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

随机推荐

  1. 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式

    一.对UITabBar背景和icon图标的一些设置 (1)由于直接给UITabBar设置的背景颜色显示的不纯.半透明的感觉,所以,有时候我们能够直接利用纯色的图片作为背景达到想要的效果. (2)给ic ...

  2. Python string replace 方法

    Python string replace   方法 方法1: >>> a='...fuck...the....world............' >>> b=a ...

  3. Android菜鸟的成长笔记(1)——Android开发环境搭建从入门到精通

    原文:Android菜鸟的成长笔记(1)--Android开发环境搭建从入门到精通 今天在博客中看到好多Android的初学者对Android的开发环境的搭建不熟悉而导致不能进行学习,所以我决定自己写 ...

  4. Redis Destop Manager不能访问虚拟机

    虚拟机centOS中安装Redis,主机Redis Destop Manager不能访问虚拟机Redis server的解决方案 今天在学些redis的时候碰到个问题,发现主机Redis Destop ...

  5. SVM入门(十)将SVM用于多类分类

    源地址:http://www.blogjava.net/zhenandaci/archive/2009/03/26/262113.html 从 SVM的那几张图可以看出来,SVM是一种典型的两类分类器 ...

  6. 运行Dos命令并得到dos的输出文本(使用管道函数CreatePipe和PeekNamedPipe)

    function RunDOS(const CommandLine: string): string;var  HRead, HWrite: THandle;  StartInfo: TStartup ...

  7. URL加随机数的作用

    原文:URL加随机数的作用 大家在系统开发中都可能会在js中用到ajax或者dwr,因为IE的缓存,使得我们在填入相同的值的时候总是使用IE缓存,为了解决这个问题一般可以用一下方法:        1 ...

  8. ABAP 中 Table Control例子

    实现了Table Control的主要的一些功能,可以作为例子参考,实现的功能有是否可编辑切换,选择某一条记录点击按钮显示详细信息,新增记录,删除记录,选择所有记录,选择光标所有记录,取消选择所有,排 ...

  9. webmagic加上了注解支持

    今天有个网友在博客回帖,能不能用注解来写一个爬虫?想了想,因为Javaer总习惯结果有个对象Model(我在自己用的时候也是这样),ResultItems的key-value形式难免会有点麻烦,何不将 ...

  10. POJ2112_Optimal Milking(网洛流最大流Dinic+最短路Flody+二分)

    解题报告 农场有k个挤奶机和c头牛,每头牛到每一台挤奶机距离不一样,每台挤奶机每天最多挤m头牛的奶. 寻找一个方案,安排每头牛到某一挤奶机挤奶,使得c头牛须要走的全部路程中的最大路程的最小值. 要使每 ...