2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)

Posted 1013star

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)相关的知识,希望对你有一定的参考价值。

What time is it anyway?

  •  524288K
 

The  ext{Frobozz Magic Clock Company}Frobozz Magic Clock Company makes 12-hour analog clocks that are always circular and have an hour hand and a minute hand as shown below:

技术分享图片

The shop has NN clocks all possibly showing different times. The clocks show different times so the customers can see what the otherwise identical clocks would look like at different times. Each clock has a label card that is supposed to be affixed to the back of the clock indicating the  ext{time difference}time difference from the correct time.

Before beginning his trek across the  ext{Eastlands, Lord Dimwit Flathead}Eastlands, Lord Dimwit Flathead worked at the  ext{Frobozz Magic Clock Company}Frobozz Magic Clock Company for less than a single day in 741 GUE when he was summarily fired for removing all the labels from backs of the clocks "in order to clean them", or so he says. The labels were strewn about the floor as a result of Dimwit‘s "cleaning" process. In order to replace each label on its respective clock, it would be a great help to know the current time. This is where you come in. You will write a program to print out the correct time given the time shown on each clock and the time differences shown on the labels. Note the labels are mixed up and you do not know which clock they belong to.

Input

The first line of input contains a single decimal integer PP, (1 le P le 10000)(1P10000), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of multiple lines of input. The first line contains the data set number, KK, followed by the number of clocks, NN, (1 le N le 10)(1N10). The next NN lines each specify the time on a clock in the form  ext{H:MM}H:MM, (1 le H le 12, 0 le MM le 59)(1H12,0MM59). The next NN lines each specify an offset from the current time in the form [+/-] ext{h:mm}h:mm, (0 le h le 10000, 0 le mm le 59)(0h10000,0mm59). MMMM and mmmm are zero padded to 2 digits on the left, so 9 would be 09 and 11 would be 11.

Output

For each data set there is a single line of output.

The single line of output consists of the data set number, KK, followed by a single space followed by the current time for the given data set. If no time can be found to match input data, then the output is the data set number, KK, followed by a single space followed by the word "none". If more than one time is found that satisfies the input data, then the output is the data set number, KK, followed by a single space followed by the number of different times that match the input data.

样例输入

3
1 2
1:05
8:35
-3:15
+1:15
2 2
3:00
9:00
+3:00
-3:00
3 2
3:00
9:00
+6:00
-6:00

样例输出

1 11:50
2 2
3 none

题目来源

2018 ICPC Greater New York Regional Contest

题意:给你n个已知的时间,和n个这些时间与正确时间可能存在的偏差,问你有没有某种匹配的方案使得这些正确的时间唯一,若没有,输出none,唯一,输出该正确时间,若有多种可能,输出有几种可能性。

题解:

  本题如何让n个时间和n个偏差值互相匹配为难点,但是大神队友一眼看出这不就是个so easy的暴搜嘛。。。orz 好吧,本蒟蒻真的是太辣鸡了嘤嘤嘤。然后怎么让这些时间和偏差值相加减,大神队友说全换算成分钟相加,相减就减完再加上720,然后再把分钟换算成几小时几分钟。暴搜就是每次固定一个正确的时间,看看是否可以匹配n个就好了。

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 using namespace std;
  6 struct node{
  7     int h;
  8     int mm;
  9     int flag;
 10 }f[20],s[20];
 11 int casen;
 12 int n;
 13 int ans;
 14 int ansh,ansmin;
 15 int vis[30];
 16 node cal(node x,node y)
 17 {
 18     int sum=0;
 19     int t1=(x.h%12)*60+x.mm;
 20     int t2=(y.h%12)*60+y.mm;
 21     if(y.flag==1)
 22     {
 23         sum=t2+t1;
 24     }
 25     else
 26     {
 27         sum=t1-t2+720;
 28     }
 29     node tmp;
 30     tmp.h=(sum/60)%12;
 31     if(tmp.h==0)
 32         tmp.h=12;
 33     tmp.mm=sum%60;
 34     return tmp;
 35 }
 36 void dfs(int pos,int hh,int min)
 37 {
 38     if(pos>=n)
 39     {
 40         if(ans==0)
 41         {
 42             ans=1;ansh=hh,ansmin=min;
 43         }
 44         else
 45         {
 46             if(ansh!=hh||ansmin!=min)
 47                 ans++;
 48         }
 49     }
 50     for(int i=0;i<n;i++)
 51     {
 52         if(!vis[i])
 53         {
 54             node now=cal(f[pos],s[i]);
 55             if(!pos||(now.h==hh&&now.mm==min))
 56             {
 57                 vis[i]=1;
 58                 dfs(pos+1,now.h,now.mm);
 59                 vis[i]=0;
 60             }
 61         }
 62         
 63     }
 64 }
 65 int main()
 66 {
 67     int k;
 68     char ch;
 69     scanf("%d",&casen);
 70     while(casen--)
 71     {
 72         scanf("%d%d",&k,&n);
 73         for(int i=0;i<n;i++)
 74         {
 75             scanf("%d:%d",&f[i].h,&f[i].mm);
 76         }
 77         for(int i=0;i<n;i++)
 78         {
 79             getchar();
 80             scanf("%c%d:%d",&ch,&s[i].h,&s[i].mm);
 81             if(ch==+)
 82             {
 83                 s[i].flag=-1;
 84             }
 85             else
 86             {
 87                 s[i].flag=1;
 88             }
 89         }
 90         ans=0;
 91         memset(vis,0,sizeof(vis));
 92         dfs(0,0,0);
 93         printf("%d ",k);
 94         if(ans==0)
 95         {
 96             puts("none");
 97         }
 98         else if(ans==1)
 99         {
100             printf("%d:%02d
",ansh,ansmin);
101         }
102         else
103         {
104             printf("%d
",ans);
105         }
106     }
107 }

 

以上是关于2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)的主要内容,如果未能解决你的问题,请参考以下文章

2018ICPC南京网络赛

2018 ICPC 沈阳网络赛

2018 ICPC 徐州网络赛

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

ICPC 2018 徐州赛区网络赛

2018-2019 ICPC, NEERC, Southern Subregional Contest