Hartals

PC/UVa 题号:110203/10050 题目描述

#include <iostream>
#include <vector>

using namespace std;

void hartal(vector<bool> & days, int h) {
  int n = days.size();
  int t = h - 1;
  while (t < n) {
    int r = t % 7;
    if (r != 5 && r != 6)
      days[t] = true;
    t += h;
  }
}

int main() {
  int t;
  if (cin >> t) {
    for (int i = 0; i < t; i++) {
      int n, p;
      vector<bool> days;
      cin >> n >> p;
      days.resize(n, false);
      for (int j = 0; j < p; j++) {
        int h;
        cin >> h;
        hartal(days, h);
      }
      int count = 0;
      for (int j = 0; j < n; j++) {
        if (days[j])
          count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}

《Hartals》有1个想法

  1. Pingback: 目录 | 狂童

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>