uva 10050 - Hartals

  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 (

)
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 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 (

).

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 <iostream>
#include <stack>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <stack>
#include <list>
#include <sstream>

using namespace std;

#define ms(arr, val) memset(arr, val, sizeof(arr))
#define N 4000
#define INF 0x3fffffff
#define vint vector<int>
#define setint set<int>
#define mint map<int, int>
#define lint list<int>
#define sch stack<char>
#define qch queue<char>
#define sint stack<int>
#define qint queue<int>

int days[N];
int hoy[N];
int main()
{
    int t, p, h, n, ans;
    ms(hoy, 0);
    for (t = 6; t <= 3650; t += 7)
    {
        hoy[t] = hoy[t + 1] = 1;
    }
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        scanf("%d", &p);
        ms(days, 0);
        while (p--)
        {
            scanf("%d", &h);
            for (int i = h; i <= n; i += h)
            {
                days[i] = 1;
            }
        }
        ans = 0;
        for (int i = 1; i <= N; i++)
        {
            if (days[i] && !hoy[i])
                ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

uva 10050 - Hartals

时间: 2024-08-16 16:11:09

uva 10050 - Hartals的相关文章

UVA 10050 Hartals (罢工指数,暴力枚举。)

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 num

UVa 10050 罢工

题意:就是给定一个范围的时间段,第一天是周日,然后周五周六是不会罢工的.有几个党派,他们会每个hi天发起罢工,每个党派有一个hi值.这样,求给定天数中的罢工天数. 思路:从1到n循环天的编号,如果是周五周六(模7等于6或0),则不罢工:如果是其中某个hi的倍数,则必罢工. 这个应该是水题了吧..虽然开始可能会想到计数问题那个复杂的东西~ Code: #include<stdio.h> int main() { int t; scanf("%d",&t); while

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

计划,,留

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 一.<算法竞赛入门经典> 刘汝佳 (UVaOJ 351道题) 以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html "AOAPC I"

算法竞赛入门经典+挑战编程+USACO

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发.   一.UVaOJ http://uva.onlinejudge.org  西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ.   二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html   "AO

(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html “AOAPC I”是刘汝佳(大

UVA Problem D: Hartals

题目如下: 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 denot

uva 10154 - Weights and Measures【dp】qi

题意:uva 10154 - Weights and Measures 题意:有一些乌龟有一定的体重和力量,求摞起来的最大高度.力量必须承受其上面包括自己的全部的重量. 分析:先按其能举起来的力量从小到大排序 然后定义dp[i] 表示摞起来 i 只乌龟的最小质量. 然后转移就是每次用遍历O(n)的复杂度找最小的,然后记录,保存最大值即可. AC代码: #include<iostream> #include<cstdio> #include<cstring> #inclu