PC/UVA 110203/10050
裸的bfs
//author: CHC
//First Edit Time: 2014-01-17 12:12
//Last Edit Time: 2014-01-17 12:36
//Filename:1.cpp
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
struct po
{
int cur;//第几天
int day;//0~6代表星期天到星期六
int jg;
};
int ha[4000];
queue <po> q;
int n,p;
int bfs(){
po now;
int num=0;
while(!q.empty()){
now=q.front();
q.pop();
if(now.cur>n)continue;
if(!ha[now.cur]&&now.day!=5&&now.day!=6)++num;
ha[now.cur]=1;
now.cur+=now.jg;
now.day=(now.day+now.jg)%7;
q.push(now);
}
return num;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
scanf("%d",&p);
while(!q.empty())q.pop();
memset(ha,0,sizeof(ha));
for(int i=0,x;i<p;i++)
{
scanf("%d",&x);
po tmp;
tmp.cur=x;
tmp.day=(x-1)%7;
tmp.jg=x;
q.push(tmp);
}
printf("%d\n",bfs());
}
return 0;
}
Political parties in Bangladesh show their muscle by calling for regular hartals (strikes), which cause considerable economic damage. For our purposes, each party may be characterized by a positive integer h called the hartal parameter that denotes the average number of days between two successive strikes called by the given party. Consider three political parties. Assume h1 = 3, h2 = 4, and h3 = 8, where hi is the hartal parameter for party i. We can simulate the behavior of these three parties for N = 14 days. We always start the simulation on a Sunday. There are no hartals on either Fridays or Saturdays.
There will be exactly five hartals (on days 3, 4, 8, 9, and 12) over the 14 days. There is no hartal on day 6 since it falls on Friday. Hence we lose five working days in two weeks. Given the hartal parameters for several political parties and the value of N, determine the number of working days lost in those N days. InputThe 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 OutputFor each test case, output the number of working days lost on a separate line. Sample Input2 14 3 3 4 8 100 4 12 15 25 40 Sample Output5 15 |