10050 - Hartals
来源:互联网 发布:小天才手表显示无网络 编辑:程序博客网 时间:2024/05/16 07:45
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).
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 ( ) giving the number of days over which the simulation must be run. The next line contains another integer P ( ) representing the number of political parties in this case. The ith 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 ( ).
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
2143348100412152540
Sample Output
515
题意:有N天,按照星期天开始依次排序,规定周五周六为休息日。然后给出几组数字,使得在这些数字的倍数的天数上为矿工日。然后求出一共有多少工作日变成了矿工日。
#include<iostream>#include<cmath>#include<cstdio>using namespace std;int a[100000];int main (){ int t,n,p,i; cin>>t; while(t--) { cin>>n; for (i=0; i<=n; i++) a[i]=0; cin>>p; int k,sum=0; while(p--) { cin>>k; for (i=k; i<=n; i+=k) if (!a[i] && i%7!=6 && i%7) { a[i]=1; sum++; } } cout<<sum<<endl; } return 0;}
- 10050 Hartals
- 10050 - Hartals
- 10050 - Hartals
- 10050 - Hartals
- 10050 - Hartals
- uva 10050 - Hartals
- UVa 10050 - Hartals
- uva 10050 - Hartals//水题
- UVa 10050 - Hartals
- UVA 10050 - Hartals
- uva 10050Hartals
- uva-10050 Hartals
- UVa 10050 - Hartals
- UVA 10050 Hartals
- uva 10050 - Hartals
- uva 10050 Hartals
- uva 10050Hartals
- UVa 10050 Hartals
- hdu2100Lovekey
- 魔方阵算法及C语言实现
- HDU 4508 湫湫系列故事——减肥记I
- phpmyadmin:Call to undefined function __() Config.class.php on line 755 解决办法
- 【随机化算法】
- 10050 - Hartals
- C语言信号-捕捉子进程退出的信号
- Maya: 菜单Create > Subdiv Primitives > Sphere
- 深入云存储系统Swift存储节点:存储实现分析
- C语言信号量实现两线程循环打印
- 字符编码
- 数论四大定理小结(初级)
- 深入云存储系统Swift核心组件:Ring数据结构及构建、重平衡操作
- Maya: 菜单Create > Volume Primitives > Sphere