新聞| | PChome| 登入
2012-09-26 08:27:55| 人氣5,864| 回應6 | 上一篇 | 下一篇

[UVA] 10050 - Hartals

推薦 0 收藏 0 轉貼0 訂閱站台

  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 integer h (called the hartal parameter) that denotes the average number of days between two successive hartals (strikes) called by the corresponding party. Though the parameter is far too simple to be flawless, it can still be used to forecast the damages caused by hartals. The following example will 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 parties for N = 14 days. One must always start the simulation on a Sunday and assume that there will be no hartals on weekly holidays (on Fridays and Saturdays).


  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 days 3, 4, 8, 9 and 12) in 14 days. There will be no hartal on day 6 since it is a Friday. Hence we lose 5 working days in 2 weeks.

In this problem, given the hartal parameters for several political parties and the value of N, your job 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 number of test cases to follow.

The first line of each test case contains an integer N ( $7 le N le 3650$) giving the number of days over which the simulation must be run. The next line contains another integer P ( $1 le P le 100$) representing the number of political parties in this case. The i­th of the next P lines contains a positive integer hi (which will never be a multiple of 7) giving the hartal parameter for party i ( $1 le i le
P$).

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

給定不執行工作的日期倍數, 而且六日本來就不執行工作, 請問總共會喪失幾天日子,
簡單用陣列標記即可

#include<stdio.h>
int main() {
int T, N, P;
scanf("%d", &T);
while(T--) {
int Day[3651] = {0}, i, x, tmp;
scanf("%d %d", &N, &P);
for(i = 0; i < P; i++) {
scanf("%d", &x), tmp = x;
while(x <= N)
Day[x] = 1, x = x+tmp;
}
int count = 0;
for(i = 1; i <= N; i++)
if(Day[i] == 1 && i%7 != 0 && i%7 != 6)
count++;
printf("%d\n", count);
}
return 0;
}
 

台長: Morris
人氣(5,864) | 回應(6)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][匈牙利二分匹配] 11138 - Nuts and Bolts
此分類上一篇:[UVA] 10170 - The Hotel with Infinite Rooms

seo
Fine Posting, We're an important believer around writing commentary for web pages so that you can allow the site freelancers realise that they’ve increased a little something valuable so that you can the ether! weed carts battery http://www.lasvegasoptic.com/top-weed-carts-12-brands-you-must-try-this-2025/article_eb4e168c-b8d3-11ef-8e17-8f30cd7b1141.html
2025-05-25 20:41:15
seo
Fine Posting, We're an important believer around writing commentary for web pages so that you can allow the site freelancers realise that they’ve increased a little something valuable so that you can the ether! thc gummies maine http://www.stoughtonnews.com/5-must-try-thc-gummies-in-2024-for-cannabis-enthusiasts/article_2707b8aa-75e9-11ef-9d12-e3b69b1496a0.html
2025-05-26 20:15:24
seo
Thank you so much meant for ad an extremely terrific report! I recently found your blog post perfect for my best necessities. It contains terrific together with practical articles or blog posts. Stick to beneficial financial job! sexy underwear for women https://www.amazon.com/NE-Beauty-Grazing-Station-Womens/dp/B0DQX9111Q/
2025-06-24 21:15:44
seo
I just got here onto your blog page whereas keeping solely to some degree submits. Decent strategy for following that, I will be bookmarking without delay grab a accomplish soars. mfkn disposable http://meridian-puff.com/product-category/mfkn-disposable/
2025-06-25 19:55:44
DASFDSFDS
Thanks for your time designed for advertisment a great very good guide! I noticed your internet-site ideal for a must have. It has splendid and even effective content articles. Compete the best get the job done! IPTV UK http://xtremehd-uk.uk/
2025-07-08 14:52:16
asdads
Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. situs toto http://spiritualedge.org/contact
2025-07-14 18:06:29
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文