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

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)(1≤P≤10000), 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)(1≤N≤10). 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)(1≤H≤12,0≤MM≤59). 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)(0≤h≤10000,0≤mm≤59). 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 }

原文地址:https://www.cnblogs.com/1013star/p/10089103.html

时间: 2024-10-03 14:30:54

2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)的相关文章

Poj(2407),Greater New York Regional 2015 (D)

题目链接:http://poj.org/problem?id=2407 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13599   Accepted: 6772 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers

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

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Krak&#243;w

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik's RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C

2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine the area of the largest triangle that can be formed using \(3\) of those \(N\) points. If there is no triangle that can be formed, the answer is \(0\

2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】

2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North America - Rocky Mountain 开始时貌似是UVAlive挂了,无论交什么都WA,后来转战HDU 这次水题比较多,其中B题据说有更加高级的方法. G题WA了两发,才发现竟然没有输出Case!!! 未完成:D F H I J A - Iterated Difference 水题,模拟迭代即可

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b

2018 ICPC 徐州网络赛

2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution 将环变成链,设\(f[i][0\)~\(2]\),分别表示与第一个数相同,与第一个数不同,与第一个数相同,与第一个数的反相同.然后\(dp\)即可. 时间复杂度:\(O(n)\) B. BE, GE or NE solution 根据题目描述\(dp\)即可. 时间复杂度:\(O(nm)\) C.

2016ACM/ICPC亚洲区青岛站 Coding Contest 费用流

目录 2016ACM/ICPC亚洲区青岛站 Coding Contest 费用流 题目描述 题意(博主的鬼畜翻译): 分析: 代码 2016ACM/ICPC亚洲区青岛站 Coding Contest 费用流 题目描述 题目描述 A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there w

2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)

2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) A 题意:有 n 个时刻,第 i 个时刻要么会在 (xi,yi) 生成一个半径为 yi 的圆,要么射击 (xi,yi) 这个点,如果该点在某个圆内则把对应圆删除并输出该圆的标号,否则输出 -1 .任意时刻圆之间不会相交(可以相切). \(n \le 2*10^5, -10^9 \le x_i,y_i \le 10^9, y