Contaminated Milk

题目描述

Farmer John, known far and wide for the quality of the milk produced on his farm, is hosting a milk-tasting party for N of his best friends (1≤N≤50). Unfortunately, of the M types of milk featured at the party (1≤M≤50), exactly one of them has gone bad, but Farmer John does not know which one! Anyone who drinks the bad milk will later become sick, either during the remainder of the party or afterward.

You are given a transcript of the party -- who drinks what when, and also who gets sick when. Based on this information, you can deduce which of the milks could possibly be the bad one. Using this knowledge, help Farmer John determine the minimum number of doses of medicine he will need to obtain in order to guarantee that he can cure all of the individuals who become sick, either during or after the party.

输入

The first line of the input contains integers N, M, D, and S.

The next D lines (1≤D≤1000) each contain three integers p,m,t, indicating that person p drank milk m at time t. The value of p is in the range 1…N, m is in the range 1…M, and t is in the range 1…100. A person may drink the same milk several times, and may also drink several types of milk at the same point in time.

The next S lines (1≤S≤N) each contain two integers p,t, indicating that person p gets sick at time t. The value of p is in the range 1…N, and t is in the range 1…100. Each person gets sick at most once, and they only get sick because they drank the bad milk at some strictly earlier point in time.

输出

A single integer, specifying the minimum number of doses of medicine Farmer John needs to obtain so that he can guarantee that he will have sufficiently many doses to treat all the people who become sick, both during and after the party.

样例输入

3 4 7 2
1 1 1
1 4 1
1 3 4
1 2 2
3 1 3
2 1 5
2 2 7
1 3
2 8

样例输出

3

提示

There are 3 people and 4 milk types. Person 1 gets sick at time 3 and person 2 gets sick at time 8. Person 3 does not get sick at the party, although we may still need to consider the possibility that he could become sick later, after the party ends. Let's consider the milk types one by one to see which ones could be contaminated; we know a milk type is potentially bad if everyone who became sick drank that milk type before becoming sick.

Milk 1: Both of the sick people (1 and 2) drank this milk before getting sick, so this could be the bad milk. If so, person 3 also drank it, so it would cause a total of 3 people to get sick (person 3 would become sick after the party).

Milk 2: Both of the sick people drank this milk before getting sick, so this could also be the bad milk. Nobody else drank this milk, so at worst 2 total people could be sick if this is the bad milk.

Milk 3: This cannot be the bad milk because person 1 did not drink it before getting sick -- person 1 drank it at time 4, and got sick at time 3. For milk 3 to be implicated in person 1 getting sick, person 1 would have needed to drink this milk by time 2 at the latest.

Milk 4: This cannot be the bad milk because person 2 did not drink it, and yet person 2 became sick.

The answer is therefore that Farmer John must obtain 3 doses of medicine, since if milk 1 is bad, then a total of 3 people will need to be cured.

分析:可能为毒牛奶的是生病的人发病前都喝的奶,对可能为毒牛奶的取最大喝的人数,注意细节处理;

代码:

#include <bits/stdc++.h>
const int maxn=1e3+;
using namespace std;
int n,m,k,t,d,s,he[maxn],he1[maxn],ma;
vector<pair<int,int> >person[maxn];
set<int>pk[maxn];
int main()
{
int i,j;
scanf("%d%d%d%d",&n,&m,&d,&s);
while(d--)
{
int p,m,t;
scanf("%d%d%d",&p,&m,&t);
if(pk[p].find(m)==pk[p].end())pk[p].insert(m),he[m]++;
person[p].push_back(make_pair(m,t));
}
for(i=;i<=s;i++)
{
int p,m;
set<int>ca;
scanf("%d%d",&p,&m);
for(auto q:person[p])
{
if(q.second<m&&ca.find(q.first)==ca.end())he1[q.first]++,ca.insert(q.first);
}
}
for(i=;i<=m;i++)
{
if(he1[i]==s)ma=max(ma,he[i]);
}
printf("%d\n",ma);
//system("pause");
return ;
}

Contaminated Milk的更多相关文章

  1. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1017  Solved: ...

  2. POJ 3261 Milk Patterns 后缀数组求 一个串种 最长可重复子串重复至少k次

    Milk Patterns   Description Farmer John has noticed that the quality of milk given by his cows varie ...

  3. 【BZOJ-1717】Milk Patterns产奶的模式 后缀数组

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 881  Solved:  ...

  4. 后缀数组---Milk Patterns

    POJ  3261 Description Farmer John has noticed that the quality of milk given by his cows varies from ...

  5. Milk

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...

  6. POJ 3261 Milk Patterns (求可重叠的k次最长重复子串)+后缀数组模板

    Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7586   Accepted: 3448 Cas ...

  7. 洛谷P1215 [USACO1.4]母亲的牛奶 Mother's Milk

    P1215 [USACO1.4]母亲的牛奶 Mother's Milk 217通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 ...

  8. 【BZOJ】【1717】【USACO 2006 Dec】Milk Patterns产奶的模式

    后缀数组 o(︶︿︶)o 唉傻逼了一下,忘了把后缀数组的字典范围改回20001,直接21交了上去,白白RE了两发……sigh 既然要找出现了K次的子串嘛,那当然要用后缀数组了>_>(因为我 ...

  9. HDU1070 Milk 细节决定成败

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070 注意:1.喝到第五天,第六天就不喝了  2.相同花费的,优先考虑容量大的  3.注意强制类型转换 ...

随机推荐

  1. 使用 Flex 库项目---打包swc

    来源:http://help.adobe.com/zh_CN/flashbuilder/using/WSe4e4b720da9dedb5-1a92eab212e75b9d8b2-7ffe.html   ...

  2. word转pdf swf 在线预览

    来源:http://www.cnblogs.com/wuhenke/archive/2010/08/01/1789750.html 之前在项目中研究使用了一套word转PDF,然后将PDF转成SWF的 ...

  3. 【读书笔记】C Primer Plus ch.15位运算 示例程序15.1 整数转换成二进制字符串

    正文: https://www.zybuluo.com/RayChen/note/595213

  4. TOMCAT 优化设置

    增加JVM堆内存大小修复JRE内存泄漏线程池设置压缩数据库性能调优Tomcat本地库 第1步 – 提高JVM栈内存Increase JVM heap memory 你使用过tomcat的话,简单的说就 ...

  5. 矩阵类c++实现

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  6. centos主机信任

    一.实现原理 使用一种被称为"公私钥"认证的方式来进行ssh登录."公私钥"认证方式简单的解释是: 首先在客户端上创建一对公私钥(公钥文件:~/.ssh/id_ ...

  7. [DP]一道理想收入问题【转】

    题意:以一元为本金,能获得的最大收入,第i天股票价格为v[i],1<=i<=m 思路: (1)DP思路明显,直接进行动态规划,令f[i]代表第i天所获得的最大收入.那么有公式: f[i] ...

  8. checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=

    在对php进行安装的过程中出现如下错误: 1.报错信息: 1 checking for known struct flock definition... configure: error: Don't ...

  9. 怎样解决VS2013模块对于SAFESEH 映像是不安全的

    今天在使用VS2013编译一个控制台应用程序时出现了:error LNK2026 模块对于 SAFESEH 映像是不安全的,按照以下步骤轻松解决了. 打开该项目的“属性页”对话框,然后单击“链接器”- ...

  10. javaweb 国际化

    国际化又称为 i18n:internationalization 软件实现国际化,需具备哪些特征:对于程序中固定使用的文本元素,例如菜单栏.导航条等中使用的文本元素.或错误提示信息,状态信息等,需要根 ...