UVA 10050 Hartals (罢工指数,暴力枚举。)
来源:互联网 发布:wp软件开发 编辑:程序博客网 时间:2024/05/17 00:07
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 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:Hartals
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 thehartal 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题目大意:
给你一个连续的天数,在星期六和星期五是休息,罢工是没用的。再给你P个组织,每个组织给你一个数字,表示在这个数字的倍数上此政党会罢工。问你这些天内罢工的总天数。
解题思路:
暴力枚举,注意,可能多个组织在同一天罢工,这只算一天。
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ int t,num,p[110]; bool visited[5000]; cin>>t; while(t--){ int cnt=0,nump; cin>>num>>nump; memset(visited,false,num+1); for(int i=0;i<nump;i++) cin>>p[i]; for(int i=0;i<nump;i++){ for(int j=1;j<=num;j++){ if(j%p[i]==0&&j%7!=6&&j%7!=0&&!visited[j]){ cnt++; visited[j]=true; } } } cout<<cnt<<endl; } return 0;}
- UVA 10050 Hartals (罢工指数,暴力枚举。)
- UVa Problem 10050 Hartals (罢工)
- uva 10050 Hartals(枚举)
- 2.8.3 罢工 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
- UVa 10050 - Hartals
- android 的 setTag
- 在SpringMVC中将view的数据封装成Model的方法
- Nginx源码分析一
- JavaSe基础XX21——反射机制
- django 信号机制
- UVA 10050 Hartals (罢工指数,暴力枚举。)
- nyoj 喷水装置(一)(简单的贪心)
- 黑马程序员——99乘法表
- 关于java中 try和finally return的问题
- PassValue实现了以下iOS页面间传值
- java 代码里面static程序段执行顺序
- 黑马程序员——从键盘接受一个数字,打印该数字表示的时间,最大单位到天
- 《数据结构》第一章 绪论 知识结构导图——信管1133-09
- Win7专业版添加管理员