题意

有两个人想去一起看电影,然后分别给出两个人 分别喜欢看的电影都在哪些天

然后 同一个人 不能连续看两天他不喜欢的电影

求他们最多可以看多少次电影

思路

先将两人喜欢看的电影进行排序,

① 选择两个人中喜欢看的电影中的天数次序小的进行观看

②标记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 【贪心】的更多相关文章

  1. Installing Apps Kattis - installingapps (贪心 + 背包)

    Installing Apps Kattis - installingapps Sandra recently bought her first smart phone. One of her fri ...

  2. Kattis - fairdivision 【贪心】

    题意 有一堆人 要给他们的朋友 买一个生日礼物,然后 每个人 给出自己的最大负担额度 并且给出礼物总价 然后要给出一种解决方案 尽量让 所有人的支出都接近平均,如果实在无法平均,那就让 先来的人 多处 ...

  3. Kattis - entertainmentbox 【贪心】

    思路 先将 N 个 电视节目 排序 根据 结束时间 ,结束的早的 排在前面 然后 弄 K个标记 记录 结束时间 然后 遍历一下 每次 如果能插入的话 插入到 结束时间最小的那个 队列里面去然后 每次插 ...

  4. 2016 acm香港网络赛 C题. Classrooms(贪心)

    原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...

  5. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  6. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. windows快捷键之打开网络连接

      在Win 7"開始"->"执行"对话框输入"cmd"例如以下图红框所看到的,再点击"确定"button. 步骤 ...

  2. TortoiseGit 连接oschina不用每次输入username和password的方法

    每次git clone 和push 都要输入username和password.尽管安全.但在本机上每次都输有些麻烦,怎样记住username和password呢? 在网上看了各种方法,太杂,非常多可 ...

  3. 工作总结 sql 中过滤条件 中的 (where中的) and

    总结: 在where 后面做过滤的时候 如果  有 字段1 必须满足某种值   字段2 要满足 某种或某值的时候  直接   and 字段1 = ‘a’   and    字段2 = ‘b’ or 字 ...

  4. Windows App开发之编辑文本与绘制图形

    编辑文本及键盘输入 相信大家都会使用TextBox,但假设要让文本在TextBox中换行该怎么做呢?将TextWrapping属性设置为Wrap,将AcceptsReturn属性设置为True就好咯. ...

  5. nginx实现某个页面http访问,其余全部跳转到https

    全站https实现某个页面可以http访问,其余全部跳转到https,注意下面的location,如果不加root 配置 找不到这个文件的server { listen ; server_name w ...

  6. SpringBoot使用MyBatis报错:Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)

    © 版权声明:本文为博主原创文章,转载请注明出处  1. 错误描述 使用SpringBoot集成MyBatis框架,并且使用 mapper-spring-boot-starter 自动生成MyBati ...

  7. angularjs2中的父子组件通信

    父组件模板中引用子组件 // father template: ... <child-item [name] = "fatherItemName" > </chi ...

  8. python截取搜索引擎关键词

    这段代码是自己学了python的基本语法之后,参考一个网上视频写的代码,功能是截取搜索引擎360的关键词. 代码: #!/usr/bin/python #encoding:utf-8 import u ...

  9. 玩转JPA(一)---异常:Repeated column in mapping for entity/should be mapped with insert=&quot;false&quot; update=&quot;fal

    近期用JPA遇到这样一个问题:Repeated column in mapping for entity: com.ketayao.security.entity.main.User column: ...

  10. HDU 5273 区间DP

    输入一组数,m次询问 问每一个询问区间的逆序数有多少 区间DP简单题 #include "stdio.h" #include "string.h" int dp ...