校省选赛第一场A题Cinema题解
今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1。
赛后,才发现,原来要freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);……
后来交了一下,Accepted了……烦恼!!!!!当是一个教训吧。
- Description
- input
- input.txt
- output
- output.txt
- Overall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favorite actors. He watched the movie trailers for the next month and wrote the following information for every movie: the movie title, the number of actors who starred in it, and the identifiers of these actors. Besides, he managed to copy the movie titles and how many actors starred there, but he didn't manage to write down the identifiers of some actors. Vasya looks at his records and wonders which movies may be his favourite, and which ones may not be. Once Vasya learns the exact cast of all movies, his favorite movies will be determined as follows: a movie becomes favorite movie, if no other movie from Vasya's list has more favorite actors.
- Help the boy to determine the following for each movie:
- whether it surely will be his favourite movie;
- whether it surely won't be his favourite movie;
- can either be favourite or not.
- Input
- The first line of the input contains two integers m and k (1 ≤ m ≤ 100, 1 ≤ k ≤ m) — the number of actors in Berland and the number of Vasya's favourite actors.
- The second line contains k distinct integers ai (1 ≤ ai ≤ m) — the identifiers of Vasya's favourite actors.
- The third line contains a single integer n (1 ≤ n ≤ 100) — the number of movies in Vasya's list.
- Then follow n blocks of lines, each block contains a movie's description. The i-th movie's description contains three lines:
- the first line contains string si (si consists of lowercase English letters and can have the length of from 1 to 10 characters, inclusive) — the movie's title,
- the second line contains a non-negative integer di (1 ≤ di ≤ m) — the number of actors who starred in this movie,
- the third line has di integers bi, j (0 ≤ bi, j ≤ m) — the identifiers of the actors who star in this movie. If bi, j = 0, than Vasya doesn't remember the identifier of the j-th actor. It is guaranteed that the list of actors for a movie doesn't contain the same actors.
- All movies have distinct names. The numbers on the lines are separated by single spaces.
- Output
- Print n lines in the output. In the i-th line print:
- 0, if the i-th movie will surely be the favourite;
- 1, if the i-th movie won't surely be the favourite;
- 2, if the i-th movie can either be favourite, or not favourite.
- Sample Input
- Input
- 5 3
- 1 2 3
- 6
- firstfilm
- 3
- 0 0 0
- secondfilm
- 4
- 0 0 4 5
- thirdfilm
- 1
- 2
- fourthfilm
- 1
- 5
- fifthfilm
- 1
- 4
- sixthfilm
- 2
- 1 0
- Output
- 2
- 2
- 1
- 1
- 1
- 2
- Input
- 5 3
- 1 3 5
- 4
- jumanji
- 3
- 0 0 0
- theeagle
- 5
- 1 2 3 4 0
- matrix
- 3
- 2 4 0
- sourcecode
- 2
- 2 4
- Output
- 2
- 0
- 1
- 1
- Hint
- Note to the second sample:
- Movie jumanji can theoretically have from 1 to 3 Vasya's favourite actors.
- Movie theeagle has all three favourite actors, as the actor Vasya failed to remember, can only have identifier 5.
- Movie matrix can have exactly one favourite actor.
- Movie sourcecode doesn't have any favourite actors.
- Thus, movie theeagle will surely be favourite, movies matrix and sourcecode won't surely be favourite, and movie jumanji can be either favourite (if it has all three favourite actors), or not favourite.
看题就看得很纠结啦~不过总体来说大概明白。
思路就是:
1.如果一个电影最好的情况都比其他电影最差的情况差,那么该电影一定不是最好的,即状态为1
2.再判断如果一个电影不满足最差的情况都比其他电影最好的情况好,那么该电影不一定是最好的,即状态为2
3.最后剩余的就是最好的了。
特别绕啦~关键在于,一定不是最好的,不一定是最好的,略坑。
- /*******************************************************************************/
- /* OS : 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 UTC 2013 GNU/Linux
- * Compiler : g++ (GCC) 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
- * Encoding : UTF8
- * Date : 2014-04-01
- * All Rights Reserved by yaolong.
- *****************************************************************************/
- /* Description: ***************************************************************
- *****************************************************************************/
- /* Analysis: ******************************************************************
- *****************************************************************************/
- /*****************************************************************************/
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<cmath>
- using namespace std;
- class Movie
- {
- public:
- string name;
- int num;
- int stat;
- int like;
- int hate;
- int zero;
- vector<int> act;
- Movie() {};
- void resiz()
- {
- act.resize(num);
- }
- };
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- int cases=0;
- int m,k,mov_num,i,j,tmp;
- int fav[120];
- vector<Movie> mv;
- while(cin>>m>>k)
- {
- memset(fav,0,sizeof(fav));
- for(i=0; i<k; i++)
- {
- cin>>tmp;
- fav[tmp]=1;
- }
- cin>>mov_num;
- mv.clear();
- mv.resize(mov_num);
- for(i=0; i<mov_num; i++)
- {
- cin>>mv[i].name;
- cin>>mv[i].num;
- mv[i].resiz();
- for(j=0; j<mv[i].num; j++)
- {
- cin>>mv[i].act[j];
- }
- }
- int maxlike=-1;
- int minlike=-1;
- for(i=0; i<mov_num; i++)
- {
- mv[i].zero=0;
- mv[i].hate=0;
- mv[i].like=0;
- for(j=0; j<mv[i].act.size(); j++)
- {
- //统计0的个数
- if(mv[i].act[j]==0)
- {
- mv[i].zero++;
- }
- else
- {
- if(fav[mv[i].act[j]])
- {
- mv[i].like++;
- }
- else
- {
- mv[i]. hate++;
- }
- }
- }
- }
- for(i=0; i<mov_num; i++)
- {
- int tmpbest=mv[i].like+min(mv[i].zero,k-mv[i].like); //最好的情况
- int tmpworst=mv[i].like+max(0,mv[i].zero-(m-k-mv[i].hate)); //最坏的情况
- int cnt=0;
- for(j=0; j<mov_num; j++)
- {
- if(i!=j)
- {
- if(tmpbest<mv[j].like+max(0,mv[j].zero-(m-k-mv[j].hate)))
- {
- mv[i].stat=1; //不满足最好的大于其他最小的,那么肯定不是最好的
- break;
- }
- }
- }
- for(j=0; j<mov_num&&mv[i].stat!=1; j++)
- {
- if(i!=j)
- {
- if(tmpworst<mv[j].like+min(mv[j].zero,k-mv[j].like))
- {
- mv[i].stat=2 ; //不满足最差的大于其他最好的,那么这个就肯定不是最好的!同时又不是最差的,那么就是不确定的
- break;
- }
- }
- }
- mv[i].stat= mv[i].stat>=1?mv[i].stat:0; //如果没有被确定不是最好的或者未确定的,那么就是最右的
- }
- for(i=0; i<mov_num; i++)
- {
- cout<<mv[i].stat<<endl;
- }
- }
- return 0;
- }
校省选赛第一场A题Cinema题解的更多相关文章
- 校省选赛第一场D题TwoDecks题解
今天晚上第二场比赛,现在还是赛后刷上次的题目,越刷越伤心,发现我赛后一次AC的功力很强大啊!!!(希望今晚变成是赛中一次AC啊!!) 好啦,回归正题. 看题目 D. Merging Two Decks ...
- 校省选赛第一场C题解Practice
比赛时间只有两个小时,我没有选做这题,因为当时看样例也看不懂,比较烦恼. 后来发现,该题对输入输出要求很低.远远没有昨天我在做的A题的麻烦,赛后认真看了一下就明白了,写了一下,一次就AC了,没问题,真 ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- 2019年牛客多校第一场B题Integration 数学
2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...
- 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学
牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...
- HDU6578 2019HDU多校训练赛第一场 1001 (dp)
HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...
- HDU6579 2019HDU多校训练赛第一场1002 (线性基)
HDU6579 2019HDU多校训练赛第一场1002 (线性基) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题意: 两种操作 1.在序列末 ...
- 【2019多校第一场补题 / HDU6578】2019多校第一场A题1001Blank——dp
HDU6578链接 题意 有一串字符串,仅由 {0,1,2,3}\{0, 1, 2, 3\}{0,1,2,3} 组成,长度为 nnn,同时满足 mmm 个条件.每个条件由三个整数组成:l.r.xl.r ...
- 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)
题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...
随机推荐
- ARM学习笔记4——加载存储指令
一.字数据传送指令 作用:用于把单一的数据传入或者传出一个寄存器. 1.LDR指令 1.1.作用 根据<addr_mode>所确定的地址模式从内存中将一个32位的字段读取到目标寄存器< ...
- bat处理打开关门exe
@echo off rem rem 注释 tastkill /f /im a.exe cd %CD% %CD:~0,1%: cd %Cd%b start %CD%a.exe cd .. %CD:~0 ...
- HDOJ/HDU 1804 Deli Deli(英语单词复数形式~)
Problem Description Mrs. Deli is running the delicatessen store "Deli Deli". Last year Mrs ...
- IO流的应用————小型资源管理器
小型资源管理器 private void LoadTreeView() { DirectoryInfo dir = new DirectoryInfo(@"E:\"); Direc ...
- hadoop家族之mahout安装
步骤一.下载mahout http://www.apache.org/dyn/closer.cgi/mahout/ 我下载的是 mahout-distribution-0.9.tar.gz 16-F ...
- 动态规划---最长公共子序列 hdu1159
hdu1159 题目要求两个字符串最长公共子序列, 状态转换方程 f[i][j]=f[i-1][j-1]+1; a[i]=b[j]时 f[i][j]=MAX{f[i-1][j],f[i][j-1] ...
- 微信开发第5章 通过accesstoken获取用户基本信息并修改用户备注
在关注者与公众号产生消息交互后,公众号可获得关注者的OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的.对于不同公众号,同一用户的openid不同).公众号可通过本接口来根据Op ...
- java消息队列使用场景
http://blog.163.com/sir_876/blog/static/11705223201332444647261/ 目前能用到的比较不错的消息队列组件 ,kafka,activeMq, ...
- 通过DAC来连接SQL Server
最早知道能够使用专用管理员连接.来连接到sql server.可是一直没有成功连接过.今天又看到这个,于是想再试试. 1.通过在ssms中的"连接到server对话框"中的serv ...
- myecipse的debug调试操作方法
在myecipse如果想要查询某个变量的值,或者跟踪程序的执行流程,可以如下操作: 首先在程序中设置好断点(断点的设置方法,就是在想要设置的地方的行首双击,当一个蓝色的圆形实心图标显示出来,就证明你设 ...