标签:sys hat back pause put diff ted input single
题目:
InputThere are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
OutputFor every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
Sample Input
2 2 20 25 40 1 8
Sample Output
08:00:40 am 08:00:08 am
分析:很简单的一道dp题,单层循环一遍即可,给的测试用例都很松,对于输出格式卡的不严。
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int Time[11]={0}; //每条队伍所花的时间 6 int line[2001]={0}; //dp数组,表示到第几个人时所花的时间 7 int oneT[2001]={0}; //每个人领票所花费的时间 8 int twoT[2001]={0}; //两个人一起领票所花的时间 9 int N=0,K=0; 10 11 int main(){ 12 cin >>N; 13 for(int t=0;t<N;t++){ 14 cin >>K; 15 for(int k=0;k<K;k++){ 16 cin >>oneT[k]; 17 } 18 for(int k=0;k<K-1;k++){ 19 cin >>twoT[k]; 20 } 21 line[0]=oneT[0]; 22 line[1]=min(oneT[0]+oneT[1],twoT[0]); 23 for(int i=2;i<K;i++){ 24 line[i]=min(line[i-1]+oneT[i],line[i-2]+twoT[i-1]); 25 } 26 Time[t]=line[K-1]; 27 int second=Time[t]%60; 28 int minute=(Time[t]%3600)/60; 29 int hour=(Time[t]/60)/60+8; 30 if(hour<=12){ 31 printf("%02d:%02d:%02d am\n",hour,minute,second); 32 }else{ 33 hour-=12; 34 printf("%02d:%02d:%02d pm\n",hour,minute,second); 35 } 36 } 37 system("pause"); 38 return 0; 39 }
代码:
标签:sys hat back pause put diff ted input single
原文地址:https://www.cnblogs.com/shiyu-coder/p/13189189.html