题目来源
2018 ICPC Greater New York Regional Contest
题目复制过来有的地方不行,显示不对,既然来学习,就知道原题的样子吧~~嘻嘻~~,不过我的解释和代码都是对的。
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
题意:第一个数是样例个数,下面是给出一个数k,代表第几个样例,没啥用,给出钟表的数量,然后给出每个钟表上面的时间,然后给出时间快了还是慢了,负的是慢了,正的是快了,注意不是对应的,然后计算出正确时间,如果有多个正确时间就输出有几个,如果不可能,就输出none,输出的前面那个数就是第几个例子,就是那个没用的k。
题解:搜索标记,刚开始我用模拟撸了120多行代码,结果,不能一 一对应,凉凉,靠 难受,后来队友用搜索过了,真的是搜索没学到家,难受的一批:上代码了:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAX = 21;
struct hh{
int hh,mm;
bool flag;
}a[MAX],b[MAX];
bool vis[MAX];
int n,ans,hhh,mmm;
hh jisuan(hh a,hh b){//转换成分进行计算
hh w;
int tt;
int t1=a.hh*60+a.mm;
int t2=(b.hh%12)*60+b.mm;//题目说小时范围为10000,注意一下
if(b.flag==false) tt=t1+t2;
else tt=t1-t2;
if(tt<0) tt+=720;//小于0相当于再加12个小时,很好理解,推一下就好
w.hh=tt/60%12;//别忘了%12,这里加的时候可能会超过12个小时
w.mm=tt%60;
if(w.hh==0) w.hh=12;
return w;
}
void dfs(int cnt,int h,int m){//搜索
if(cnt==n){
if(!ans) {//第一次符合要求
ans++;
hhh=h;
mmm=m;
}
else if(h!=hhh||m!=mmm) ans++;//其他符合的要求
return;
}
for (int i = 0; i < n;i++){
if(!vis[i]){//注意标记
hh w;
w=jisuan(a[cnt],b[i]);
if(!cnt||w.hh==h&&w.mm==m){//注意第一次的处理
vis[i]=true;//标记不重复用,因为一个对应一个,题目要求的
dfs(cnt+1,w.hh,w.mm);
vis[i]=false;
}
}
}
return;
}
int main(){
int p,k;
char ch;
scanf("%d",&p);
while(p--){
scanf("%d%d",&k,&n);
for (int i = 0; i < n;i++) scanf("%d:%d",&a[i].hh,&a[i].mm);
for (int i = 0; i < n;i++) {
getchar();
scanf("%c%d:%d",&ch,&b[i].hh,&b[i].mm);
if(ch=='-') b[i].flag=false;
else b[i].flag=true;
}
memset(vis,0,sizeof(vis));//别忘了初始化
ans=0;
dfs(0,0,0);
printf("%d ",k);
if(ans==0) printf("none\n");
else if(ans==1) printf("%d:%02d\n",hhh,mmm);
else printf("%d\n",ans);
}
return 0;
}