Kattis - horrorfilmnight 【贪心】
题意
有两个人想去一起看电影,然后分别给出两个人 分别喜欢看的电影都在哪些天
然后 同一个人 不能连续看两天他不喜欢的电影
求他们最多可以看多少次电影
思路
先将两人喜欢看的电影进行排序,
① 选择两个人中喜欢看的电影中的天数次序小的进行观看
②标记FLAG 看了一个人的 下次选择另一个人的
③如果另一个人喜欢看的电影的天数次序大于上次那个人的天数次序 则返回②
④如果一个人喜欢看的电影的天数次序等于上次那个人的天数次序 则返回②
跳出循环条件
① 两个人的电影都选完了 则直接BREAK
② 两个人的电影其中一个选完,另一个人还有的选,则ANS + 1 再BREAK
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
const int MOD = 1e9 + 7;
int p[maxn], q[maxn];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &p[i]);
sort (p, p + n);
int m;
scanf("%d", &m);
for (int i = 0; i < m; i++)
scanf("%d", &q[i]);
sort(q, q + m);
int flag;
int vis = -1;
int i = 0, j = 0;
int ans = 0;
while (1)
{
if (vis == -1)
{
if ((i == n && j != m) || (i != n && j == m))
{
ans++;
break;
}
else if (i == n && j == m)
break;
if (p[i] < q[j])
{
vis = p[i];
ans++;
i++;
flag = 1;
continue;
}
else if (p[i] == q[j])
{
ans++;
i++;
j++;
continue;
}
else
{
vis = q[j];
j++;
ans++;
flag = 0;
continue;
}
}
else if(flag == 0)
{
if (i == n)
break;
for ( ; i < n; i++)
{
if (p[i] > vis)
{
vis = p[i];
i++;
ans++;
flag = 1;
break;
}
else if(p[i] == vis)
{
vis = -1;
i++;
break;
}
}
}
else if (flag == 1)
{
if (j == m)
break;
for ( ; j < m; j++)
{
if (q[j] > vis)
{
vis = q[j];
j++;
ans++;
flag = 0;
break;
}
else if(q[j] == vis)
{
vis = -1;
j++;
break;
}
}
}
}
cout << ans << endl;
}
Kattis - horrorfilmnight 【贪心】的更多相关文章
- Installing Apps Kattis - installingapps (贪心 + 背包)
Installing Apps Kattis - installingapps Sandra recently bought her first smart phone. One of her fri ...
- Kattis - fairdivision 【贪心】
题意 有一堆人 要给他们的朋友 买一个生日礼物,然后 每个人 给出自己的最大负担额度 并且给出礼物总价 然后要给出一种解决方案 尽量让 所有人的支出都接近平均,如果实在无法平均,那就让 先来的人 多处 ...
- Kattis - entertainmentbox 【贪心】
思路 先将 N 个 电视节目 排序 根据 结束时间 ,结束的早的 排在前面 然后 弄 K个标记 记录 结束时间 然后 遍历一下 每次 如果能插入的话 插入到 结束时间最小的那个 队列里面去然后 每次插 ...
- 2016 acm香港网络赛 C题. Classrooms(贪心)
原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- dr-helper项目设计介绍(一个包括移动端和Web端的点餐管理系统)
一.源代码路径 https://github.com/weiganyi/dr-helper 二.界面 通过浏览器訪问Web服务,能够看到界面例如以下: ADT-Bundle编译project生成dr- ...
- jm解决乱码问题-参数化-数据库操作-文件上传下载
jm解决乱码问题-参数化-数据库操作-文件上传下载 如果JM出果运行结果是乱码(解决中文BODY乱码的问题) 找到JM的安装路径,例如:C:\apache-jmeter-3.1\bin 用UE打开jm ...
- 笔记本中G-Sensor(加速计) M-Sensor 陀螺仪等传感器的区别与作用
1.G-sensor重力传感器 作用 G-sensor中文是加速度传感器的意思(英文全称是Accelerometer-sensor),它能够感知到加速力的变化,加速力就是当物体在加速过程中作用在物体上 ...
- atitit.bsh BeanShell 的动态脚本使用java
atitit.bsh BeanShell 的动态脚本使用java 1.1. BeanShell是一个小巧免费的JAVA源码解释器 ,支持对象式的脚本语言特性,亦可嵌入到JAVA源代码中. 亦可嵌入到J ...
- JSTL JSP页面推断某个cookie的值和读取值....
<c:if test="${cookie['woshop'].value eq '1'}"> <div> ...
- MapReduce源码分析之InputFormat
InputFormat描述了一个Map-Reduce作业中的输入规范.Map-Reduce框架依靠作业的InputFormat实现以下内容: 1.校验作业的输入规范: 2.分割输入文件(可能为多个), ...
- 使用虚拟环境 virtualenv
1.安装 $ sudo apt-get install python-virtualenv 2.重命名,一般虚拟环境会被命名为venv $ virtualenv venv 3. 激活 $ sour ...
- VSCode 运行go test显示打印日志
在VSCode中运行go test,在代码中写的 fmt.Printf("TestB \n") 这些语句均不打印,只显示最终的结果 PASS ok github.com/B .03 ...
- Oracle关于快速缓存区应用原理
为什么oracle可以对于大量数据进行訪问时候能彰显出更加出色表现,就是通过所谓的快速缓存来实现数据的快速运算与操作.在之前的博文中我已经说过sql的运行原理,当我们訪问数据库的数据时候,首先不是从数 ...
- 可执行jar包
我已经解决了这个问题,在eclipse中有一个打包工具,可以将程序打包成.jar文件: 右键要打包的 project--->Export--->Java--->JAR file--- ...