[UVa] 10050 - Hartals
- import java.util.*;
- class main{
- public static void main(String[] args){
- Scanner sc=new Scanner(System.in);
- int size = sc.nextInt();
- while(size-->0){
- int D = sc.nextInt();
- boolean[][] bs = new boolean[D/7+2][7]; //使用布林2維陣列 紀錄是否每個黨同天同週罷工
- TreeMap<Integer,Integer> ts = new TreeMap();
- int H = sc.nextInt(); //黨數
-
- while(H-->0){
- int dis = sc.nextInt(); //每黨罷工間隔
- for(int i=dis;i<=D;i+=dis){
- if(bs[i/7][(i-1)%7]==false){
- if(ts.containsKey((i-1)%7)) ts.put((i-1)%7,ts.get((i-1)%7)+1);
- else ts.put((i-1)%7,1);
- bs[i/7][(i-1)%7]=true;
- }
- }
- }
-
- int count =0;
- for(int i:ts.keySet())
- if(i!=5&&i!=6) count+=ts.get(i);
- System.out.println(count);
- }
-
- }
- }
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。