ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

E-What time is it anyway?---2018纽约区域赛(模拟暴搜)

2021-06-05 19:02:31  阅读:154  来源: 互联网

标签:What 12 00 int anyway --- set time data


What time is it anyway?

Time Limit: 1 Sec Memory Limit: 128 Mb

Description

The Frobozz Magic Clock CompanyFrobozz Magic Clock Company makes 12-hour analog clocks that are always circular and have an hour hand and a minute hand as shown below:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IcaMyxKE-1569818872268)(http://acm.csu.edu.cn:20080/upload/problem_attach/2019-03-15_BE6CEDDEABE096EA/xcfa346900b85ed132d2fb63a5ff1033155ac55e8.png.pagespeed.ic.ICi1LjiaH7.webp)]
The shop has N 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 time difference from the correct time.

Before beginning his trek across theEastlands, Lord Dimwit FlatheaEastlands, Lord Dimwit Flathead worked at the Frobozz Magic Clock CompanyFrobozz 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 P, (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, K, followed by the number of clocks, N,(1 ≤ N ≤ 10). The next N lines each specify the time on a clock in the form H:MM,(1 ≤ H ≤ 12, 0 ≤ MM ≤ 59). The next N lines each specify an offset from the current time in the form [+/-]h:mm, (0 ≤ h ≤ 10000, 0 ≤ mm ≤ 59). MM and mm 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, K, 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, K, 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, K, followed by a single space followed by the number of different times that match the input data.

Sample Input

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

Sample Output

1 11:50
2 2
3 none


题目大意是这样的:第一个数是样例个数,下面是给出一个数k,代表第几个样例,没啥用,给出钟表的数量,然后给出每个钟表上面的时间,然后给出时间快了还是慢了,负的是慢了,正的是快了,注意不是对应的,然后计算出正确时间,如果有多个正确时间就输出有几个,如果不可能,就输出none,输出的前面那个数就是第几个例子,就是那个没用的k。

emmmm。。。如果就这么直接做的话不太好做,我们可以先将所有的时间化为分钟,当然,如果该时间超过6012分钟或小于0,我们要使它回到正常的一块区域,而我们的正常区域规定为0-1260:

int deal(int x)
{
	while (x>60*12) x-=(60*12);
	while (x<0) x+=(60*12);
	if (x==0) x=12*60;
	return x;
}

注意,题目有说明小时的数据只能在1-12之间,不能有0;接下来我们就可以开始暴搜了,不过我们也可以先处理一下。先将第一个钟与所有的时间匹配,然后枚举第一个钟选择的匹配时间,接下来对2-n个钟进行暴搜:

	vis[id]=1;  //id为1号钟选中的匹配时间
	int mk=0;
	for (int i=2; i<=n; i++){//对2-n个钟进行暴搜
		mk=0;
		for (int j=1; j<=n; j++)//钟i选择了匹配时间j
		  if (!vis[j]) {
		  	if (t1[i][j]==ex) {
			    vis[j]=1;	 
		  		mk=1;break;
		  	}
		  }
		if (!mk) return 0;
	}
	return 1;

emmm。。。有点坑的是现场赛时我把vis[j]=1放在了if(t1[i][j]==ex)的前面,还tm过了好几组数据,最后还是回来才发现bug的。。。
当然,读入也有一点坑。。。在计蒜客里面的读入只需要

ch=getchar();
scanf("%c%d:%d",&ch,&h,&m);

就可以了,但在多校时它的输入非常不标准。。。所以必须换为:

            ch=getchar();
			while (ch!='+' && ch!='-') ch=getchar();
			scanf("%d:%d",&h,&m);

然后就可以AC了(* ^ ▽^ *)。接下来就是完整代码了(一般我的完整代码是没有注释的哟 ^ _^)

#include <cstdio>
#include <cstring>
using namespace std;
int time[15],t1[15][15],clock[15],v[1000],vis[15];
int n; 
int deal(int x)
{
	while (x>60*12) x-=(60*12);
	while (x<0) x+=(60*12);
	if (x==0) x=12*60;
	return x;
}
int ok(int id,int ex)
{
	vis[id]=1;
	int mk=0;
	for (int i=2; i<=n; i++){
		mk=0;
		for (int j=1; j<=n; j++)
		  if (!vis[j]) {
		  	if (t1[i][j]==ex) {
			    vis[j]=1;	 
		  		mk=1;break;
		  	}
		  }
		if (!mk) return 0;
	}
	return 1;
}
int main()
{
	int t,id;
	scanf ("%d",&t);
	for (int o=1; o<=t; o++){
		scanf ("%d%d",&id,&n);
		memset(v,0,sizeof(v));
		memset(time,0,sizeof(time));
		int h,m;
		for (int j=1; j<=n; j++){
			scanf ("%d:%d",&h,&m);
			clock[j]=h*60+m;
		}
		char s[40],ch;
		for (int j=1; j<=n; j++){
			ch=getchar();
			while (ch!='+' && ch!='-') ch=getchar();
			scanf("%d:%d",&h,&m);
			time[j]=h*60+m;
			if (ch=='+') time[j]=-time[j]; 
		}
		for (int i=1; i<=n; i++)
		 for (int j=1; j<=n; j++){
		 	 t1[i][j]=clock[i]+time[j];
		 	 if (t1[i][j]>60*12 || t1[i][j]<0) t1[i][j]=deal(t1[i][j]);
		 	 if (t1[i][j]==0) t1[i][j]=60*12;
		 }
		int num=0,ans;		  
		for (int i=1; i<=n; i++){
			memset(vis,0,sizeof(vis));
			int ye=ok(i,t1[1][i]);
			if (ye && !v[t1[1][i]]) {
				num++;
				ans=t1[1][i];
				v[t1[1][i]]=1;
			}		
		}
		if (!num) printf ("%d none\n",o);
		else if (num>1) printf ("%d %d\n",o,num);
		else {
			int hh=ans/60,mm=ans%60;
			if (hh==0) hh=12;
			printf ("%d %d:%02d\n",o,hh,mm);
		}
	}	
	return 0;
 } 

标签:What,12,00,int,anyway,---,set,time,data
来源: https://blog.51cto.com/u_15249461/2870459

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有