Hartals UVA10050
来源:互联网 发布:淘宝充话费系统 编辑:程序博客网 时间:2024/05/16 01:47
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
Miguel Revilla
2000-12-26
看懂题意就很简单了,感觉没用到什么数据结构。。直接用数组就可以过。
#include<iostream>#include<cstring>using namespace std;int arry[100];int day[3700];int main(){ int n; cin>>n; while(n--) { memset(arry,0,sizeof(arry)); memset(day,0,sizeof(day)); int m,i,h,j; cin>>m>>h; for(i=0;i<h;i++) cin>>arry[i]; for(i=0;i<h;i++) { j=0; while(j+arry[i]<=m) { day[j+arry[i]]=1; j=arry[i]+j; } } int s=0; for(i=1;i<=m;i++) { if((i%7!=0)&&(i%7!=6)) { if(day[i]==1) { s++; } } } cout<<s<<endl; } return 0;}
- uva10050 Hartals
- UVA10050 Hartals
- UVA10050- Hartals
- Hartals UVA10050
- UVA10050 Hartals
- uva10050
- uva10050
- uva10050
- hartals
- Hartals
- uva10050-罢工
- 10050 Hartals
- 10050 - Hartals
- UVaOJ10050---Hartals
- 10050 - Hartals
- 110203 Hartals
- 10050 - Hartals
- 10050 - Hartals
- 关于ios内存警告
- java异常的捕获与抛出原则
- 洗大师权限管理分析
- ListView选中一行后高亮显示(附源码)
- setjmp 与 longjmp
- Hartals UVA10050
- memcached
- hdu 2222 Keywords Search(AC自动机)
- POJ:3026 Borg Maze
- 使用MFC::CArchive
- sencha touch之表单二(注册页面)
- oracle中bulk collect into用法
- jsp只在首次加载时调用action
- 把Window设置成灰暗