zoukankan      html  css  js  c++  java
  • uva10050

    题目给出 N个天数, X个party数,然后X行是每个PARTY罢工的周期m,计算在N天内一共罢工的天数是多少,一天内如果有一个以上party罢工就算一次

    题目

     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 ( $7 le N le 3650$) giving the number of days over which the simulation must be run. The next line contains another integer P ( $1 le P le 100$) 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 ($1 le i le
P$).

    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
    

    用了一下set

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <set>
     4 #include <vector>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int tst;
    11     cin>>tst;
    12     while(tst--)
    13     {
    14         int days,party;
    15         cin>>days>>party;
    16         
    17         set<int> lost;
    18         for(int i=0;i<party;i++)
    19         {
    20                 int M,parm;
    21                 cin>>M;             //每一个paty 的罢工周期           
    22                 parm = days/M;   // 周期
    23                 for(int i=1;i<=parm;i++)
    24                 {
    25                     int hartal=M*i ;
    26                     //cout<<"hartal"<<hartal<<endl;
    27                     if(hartal%7 != 6 && hartal%7 !=0)
    28                          lost.insert(hartal);    
    29                 }          
    30         }
    31         cout<<lost.size()<<endl;
    32                 
    33     }
    34     
    35  
    36  
    37     return 0;   
    38 }
  • 相关阅读:
    php生成excel
    gearmand
    开启Nginx的目录文件列表功能
    zend框架学习
    引用方法形成树
    智能指针实现
    图文例解C++类的多重继承与虚拟继承
    CC++定位崩溃代码行的方法
    C++函数重定义、重载、重写
    勤奋吧,一天一点,努力提高基本技能。
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3421395.html
Copyright © 2011-2022 走看看