#include <iostream> using namespace std; int main() { int t,n,p,h[100],ans; cin>>t; while (t--){ cin>>n>>p; ans=0; for (int i=0;i<p;++i) cin>>h[i]; for (int i=1;i<=n;++i) if (i%7!=6 && i%7!=0) for (int j=0;j<p;++j) if (i%h[j]==0){ ++ans; break; } cout<<ans<<endl;//让人发火的是,最后一个输出如果不加空行会判错 } return 0; }
3
5
2015
5
2015
UVa 10050 Hartals
3
5
2015
5
2015
UVa 10189 Minesweeper
#include <cstdio> #define ok(p,q) p>0 && p<=n && q>0 && q<=m && a[p][q]=='*' //用宏简化代码 int n,m,x; char a[101][101]; int main() { scanf("%d%d",&n,&m); while (n!=0){ printf ("Field #%d:\n",++x); getchar(); for (int i=1;i<=n;++i,getchar()) for (int j=1;j<=m;++j) a[i][j]=getchar(); for (int i=1;i<=n;++i,putchar('\n')) for (int j=1;j<=m;++j){ if (a[i][j]=='*'){ //是雷直接输出 putchar('*'); continue; } a[i][j]='0'; //直接用ascii码操作 if (ok(i-1,j-1)) ++a[i][j]; if (ok(i-1,j)) ++a[i][j]; if (ok(i-1,j+1)) ++a[i][j]; if (ok(i,j-1)) ++a[i][j]; if (ok(i,j+1)) ++a[i][j]; if (ok(i+1,j-1)) ++a[i][j]; if (ok(i+1,j)) ++a[i][j]; if (ok(i+1,j+1)) ++a[i][j]; putchar(a[i][j]); } scanf("%d%d",&n,&m); if (n) putchar('\n'); //惨痛的教训,最后一个矩阵后不加空行 } return 0; }
3
5
2015
5
2015
UVa 10038 Jolly Jumper
#include <iostream> #include <cstdlib> #include <cstring> using namespace std; int n,a[3000]; bool b[3000]; int main() { while (cin>>n){ memset(b,0,sizeof(b)); for (int i=0;i<n;++i) cin>>a[i]; for (int i=1;i<n;++i){ int x=abs(a[i]-a[i-1]);//相邻差的绝对值 if (x==0 || x>=n || b[x]){//若x不在范围内或前面已经有过了, cout<<"Not jolly"<<endl; //肯定不是jolly jumper,跳出 goto next; } b[x]=1; } cout<<"Jolly"<<endl;//前面都没跳出,就是jolly jumper next:; } return 0; }