Contaminated Milk
Contaminated Milk
题目描述
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 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.
输出
样例输入
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的更多相关文章
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: ...
- POJ 3261 Milk Patterns 后缀数组求 一个串种 最长可重复子串重复至少k次
Milk Patterns Description Farmer John has noticed that the quality of milk given by his cows varie ...
- 【BZOJ-1717】Milk Patterns产奶的模式 后缀数组
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 881 Solved: ...
- 后缀数组---Milk Patterns
POJ 3261 Description Farmer John has noticed that the quality of milk given by his cows varies from ...
- Milk
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...
- POJ 3261 Milk Patterns (求可重叠的k次最长重复子串)+后缀数组模板
Milk Patterns Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7586 Accepted: 3448 Cas ...
- 洛谷P1215 [USACO1.4]母亲的牛奶 Mother's Milk
P1215 [USACO1.4]母亲的牛奶 Mother's Milk 217通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 ...
- 【BZOJ】【1717】【USACO 2006 Dec】Milk Patterns产奶的模式
后缀数组 o(︶︿︶)o 唉傻逼了一下,忘了把后缀数组的字典范围改回20001,直接21交了上去,白白RE了两发……sigh 既然要找出现了K次的子串嘛,那当然要用后缀数组了>_>(因为我 ...
- HDU1070 Milk 细节决定成败
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070 注意:1.喝到第五天,第六天就不喝了 2.相同花费的,优先考虑容量大的 3.注意强制类型转换 ...
随机推荐
- sql-删除delete涉及到三个表,这个时候就要使用from,比如这样
delete y from dbo.XZXK_BANJIE b ,YJDC_YELLOWRED_CONTENT y , dbo.XZXK_SHOULI s where b.shoulioid=s.sh ...
- 格式化格林威治时间(Wed Aug 01 00:00:00 CST 2012)
1.如果格林威治时间时间是date类型.(这种格式最简单) SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd") ...
- php过滤HTML标签、属性等正则表达式汇总
$str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...
- linux命令-sed,uniq,cut,wc
sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 ...
- java的两种异常runtimeException和checkedException
java异常处理机制主要依赖于try,catch,finally,throw,throws五个关键字. try 关键字后紧跟一个花括号括起来的代码块,简称try块.同理:下面的也被称为相应的块. ...
- 图像操作相关 With Quartz 2D
本文将为大家介绍常见的IOS图像处理操作包括以下四部分:旋转,缩放,裁剪以及像素和UIImage之间的转化,主要使用的知识是quartz2D.Quartz2D是CoreGraphics框架中的一个重要 ...
- Swift -> Let & Var 背后编程模式 探讨
简介 Swift中有两种声明“变量”的方式,这两种方式分别使用let和var这两个关键字.这应该是借鉴了Scala,因为它们和Scala的val和var有相同的作用.let被用于声明不变量,var被用 ...
- Swift -> RunTime(动态性) 问题 浅析
Swift是苹果2014年发布的编程开发语言,可与Objective-C共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序.Swift已经开源,目前最新版本为2.2.我们知道Objec ...
- ViewPager和View组合 实现页面的切换
//--------------主页面------------------------------- package com.bw.test; import java.util.ArrayList;i ...
- 指针--摘自C++技术网 作者dx
“指针是什么?”“指针就是一种数据类型.”“你确定?”“那数据类型是什么?额,这个???类型就是类型,还能怎么解释嘛.”“指针有多少种?”“指针有好多种,比如整型指针,字符指针等等.”“指针是怎么确定 ...