2017年9月8日 星期五

[UVa] 10050 - Hartals

  1. import java.util.*;  
  2. class main{  
  3. public static void main(String[] args){  
  4. Scanner sc=new Scanner(System.in);  
  5. int size = sc.nextInt();  
  6. while(size-->0){  
  7. int D = sc.nextInt();  
  8. boolean[][] bs = new boolean[D/7+2][7];  //使用布林2維陣列 紀錄是否每個黨同天同週罷工
  9. TreeMap<Integer,Integer> ts = new TreeMap();  
  10. int H = sc.nextInt();  //黨數
  11.   
  12. while(H-->0){  
  13. int dis = sc.nextInt();  //每黨罷工間隔
  14.  for(int i=dis;i<=D;i+=dis){  
  15.   if(bs[i/7][(i-1)%7]==false){    
  16.    if(ts.containsKey((i-1)%7)) ts.put((i-1)%7,ts.get((i-1)%7)+1);   
  17.    else ts.put((i-1)%7,1);  
  18.    bs[i/7][(i-1)%7]=true;  
  19.    }  
  20.  }  
  21. }  
  22.   
  23. int count =0;  
  24. for(int i:ts.keySet())  
  25.  if(i!=5&&i!=6) count+=ts.get(i);  
  26. System.out.println(count);  
  27. }  
  28.   
  29. }  
  30. }  

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。