码迷,mamicode.com
首页 > 其他好文 > 详细

UVA Problem D: Hartals

时间:2014-05-24 23:10:01      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:uva   acm   模拟   

题目如下:

Problem D: Hartals 

A social research organization has determined a simple set of parameters to simulate the behavior of the political parties of our country. One of the parameters is a positive integerh (called the hartal parameter) that denotes the average number of daysbetween two successive hartals (strikes) called by the correspondingparty. Though the parameter is far too simple to be flawless, it can still beused to forecast the damages caused by hartals. The following examplewill give you a clear idea:


Consider three political parties. Assume h1 = 3,h2 = 4 and h3 = 8 where hi is the hartal parameter for party i(i = 1, 2, 3). Now, we will simulate the behavior of these three partiesfor N = 14 days. One must always start the simulation on a Sunday and assumethat there will be no hartals on weekly holidays (on Fridays andSaturdays).


  1 2 3 4 5 6 7 8 9 10 11 12 13 14
Days                            
  Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
Party 1     x     x     x     x    
Party 2       x       x       x    
Party 3               x            
Hartals     1 2       3 4     5    


The simulation above shows that there will be exactly 5 hartals (on days3, 4, 8, 9 and 12) in 14 days. There will be no hartal on day 6 since itis a Friday. Hence we lose 5 working days in 2 weeks.

In this problem, giventhe hartal parameters for several political parties and the value of N, yourjob is to determine the number of working days we lose in those N days.

Input 

The first line of the input consists of a single integer T giving the numberof test cases to follow.

The first line of each test case contains an integerN (bubuko.com,布布扣)giving the number of days over which the simulationmust be run. The next line contains another integer P (bubuko.com,布布扣)representing the number of political parties in this case. The i-th of thenext P lines contains a positive integer hi (which will never be amultiple of 7) giving the hartal parameter for party i (bubuko.com,布布扣).

Output 

For each test case in the input output the number of working days we lose.Each output must be on a separate line.

Sample Input 

2
14
3
3
4
8
100
4
12
15
25
40

Sample Output 

5
15

简单的模拟题,没啥好说的,直接上代码。

AC的代码如下:


UVA Problem D: Hartals,布布扣,bubuko.com

UVA Problem D: Hartals

标签:uva   acm   模拟   

原文地址:http://blog.csdn.net/u013840081/article/details/26739921

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!