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

2
14
3
3
4
8
100
4
12
15
25
40

Sample Output

5
15

题目大意:

给你一个连续的天数,在星期六和星期五是休息,罢工是没用的。再给你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;
}
时间: 2024-12-11 11:51:57

UVA 10050 Hartals (罢工指数,暴力枚举。)的相关文章

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 t

uva 140 Bandwidth (全排列+暴力枚举)

uva 140 Bandwidth Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an ordering on the elements in V, then the bandwidth of a node v is defined as the maximum distance in the ordering between v and any node to which it

uva 10167 Birthday Cake(暴力/枚举)

uva 10167 Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100. There are 2N (N

UVa 1354 Mobile Computing[暴力枚举]

**1354 Mobile Computing** There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and make nice mobile arts of th

uva 11205 The broken pedometer(暴力枚举+子集生成)

我终于可以说这是我自己独立完成的题目了,没看题解,没看注释,虽然用的时间成了写,总归有成就感的,昨天晚上就写了个大概,有点bug,由于太晚了,而且有点困了,就去睡了,当时真是自己认真想了的,,很深入的想了,用的书上刚学会的位向量自己生成来判断的.以后都要努力自己想,自己解决,专注...深入.... 思路: 就是先算出最少用m个灯才能表示n个数字,然后找第一个数字(由许多灯组成的0,1序列)的个数为m的子 集,把这n个子集作为n个数字的下标,判断一下有没有玩去一样的,如果有的话证明这两个数字不能通

uva 565 - Pizza Anyone?(暴力枚举 + 二进制)

题目:uva 565 - Pizza Anyone?(暴力枚举 + 二进制) 题目大意:题目是说有一个人要帮他的朋友们定批萨,然后每个朋友都有自己的口味要求,问能不能定一个批萨然后满足每个朋友的至少一个要求. 能就输出所定批萨里面加的东西,,输出要求按字典序: 不能就输出:No pizza can satisfy these requests. 解题思路:这题里面有16种材料,每种材料只有取与不取的可能,这样就有 2^16 种( 0 - 2^16 - 1),枚举出每种情况然后在分别看是否能满足每

UVA 725 Division ( 找出 abcde / fghij = N的形式—— 暴力枚举 )

Division Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divide

uva 725 Division(暴力枚举)

uva 725  Division Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where . That is, abcde / fghij =

UVA 617 - Nonstop Travel(数论+暴力枚举)

题目链接:617 - Nonstop Travel 题意:给定一些红绿灯,现在速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每一个速度,去判断可不可以,最后注意下输出格式即可 代码: #include <stdio.h> #include <string.h> #include <math.h> const double esp = 1e-6; int n, vis[105]; struct D { double l; int g, y,