校省選賽第一場A題Cinema題解

來源:互聯網
上載者:User

今天是學校省選的第一場比賽,0戰績收工,死死啃著A題來做,偏偏一直WA在TES1。

賽後,才發現,原來要freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);……

後來交了一下,Accepted了……煩惱!!!!!當是一個教訓吧。

題目
Descriptioninputinput.txtoutputoutput.txtOverall 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.InputThe 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.OutputPrint 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 InputInput5 31 2 36firstfilm30 0 0secondfilm40 0 4 5thirdfilm12fourthfilm15fifthfilm14sixthfilm21 0Output221112Input5 31 3 54jumanji30 0 0theeagle51 2 3 4 0matrix32 4 0sourcecode22 4Output2011HintNote 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;}

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.