1. 程式人生 > >2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)

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

family 輸入 trigger 可能 hit open 這不 card enter

What time is it anyway?

  • 524288K

The \text{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 \text{time difference}time difference from the correct time.

Before beginning his trek across the \text{Eastlands, Lord Dimwit Flathead}Eastlands, Lord Dimwit Flathead worked at the \text{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 \text{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 [+/-]\text{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\n",ansh,ansmin);
101         }
102         else
103         {
104             printf("%d\n",ans);
105         }
106     }
107 }

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