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. 2014 Multi-University Training Contest 1 — D. Task

    题目链接:pid=4864">http://acm.hdu.edu.cn/showproblem.php?pid=4864 题目大意: 有N个机器.M个任务. 当中每一个机器有xi,y ...

  2. COCOS2D-X之帧动画的一种实现Demo

    这个Demo主要是实现帧动画,建议游戏中少用帧动画.废话少说直接上代码. 一.我们直接在COCOS2D-X自带的HelloCpp的工程中添加代码即可.我们在初始化中添加如下代码并附上图片资源. CCS ...

  3. HDU 3478 Play with Chain (Splay树)

    这种高级数据结构太难搞了.........现在还是先照着别人的代码敲,做模板..........慢慢花时间来弄懂 #include <iostream> #include <algo ...

  4. Codeforces 474B Worms 二分法(水

    主题链接:http://codeforces.com/contest/474/problem/B #include <iostream> #include <cmath> #i ...

  5. 成功为Android系统配上了GNU开发环境

             单击此处获得本文的最新更新 经过一周的艰苦努力,成功为我的小米2手机适配上了全功能的GNU开发环境,完全兼容GNU/LINUX(Android自带的bionic.linker真心不好 ...

  6. [Android学习笔记]Android Library Project的使用

    RT http://developer.android.com/tools/projects/index.html

  7. Urxvt - awesome

    Urxvt - awesome Urxvt From awesome Jump to: navigation, search rxvt-unicode (urxvt for short) is a c ...

  8. Java并发编程--Fork/Join框架使用

    上篇博客我们介绍了通过CyclicBarrier使线程同步,可是上述方法存在一个问题,那就是假设一个大任务跑了2个线程去完毕.假设线程2耗时比线程1多2倍.线程1完毕后必须等待线程2完毕.等待的过程线 ...

  9. ZooKeeper的安装、配置、启动和使用(一)——单机模式

    ZooKeeper的安装.配置.启动和使用(一)——单机模式 ZooKeeper的安装非常简单,它的工作模式分为单机模式.集群模式和伪集群模式,本博客旨在总结ZooKeeper单机模式下如何安装.配置 ...

  10. 智能手机的工业控制应用方案——SimpleWiFi在工业控制领域应用

    智能手机的工业控制应用方案——SimpleWiFi在工业控制领域应用    先上图: 现在的智能控制都是基于微控制器,随着智能的手持终端的普及,基于智能终端的控制就会越来越普遍. WIFI便是其中的一 ...