【SinGuLaRiTy-1036】 Copyright (c) SinGuLaRiTy 2017. All Rights Reserved.

小C的倍数问题

Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 32768/32768 K (Java/Others)

Problem Description

根据小学数学的知识,我们知道一个正整数x是3的倍数的条件是x每一位加起来的和是3的倍数。反之,如果一个数每一位加起来是3的倍数,则这个数肯定是3的倍数。

现在给定进制P,求有多少个B满足P进制下,一个正整数是B的倍数的充分必要条件是每一位加起来的和是B的倍数。

Input

第一行一个正整数T表示数据组数(1<=T<=20)。

接下来T行,每行一个正整数P(2 < P < 1e9),表示一组询问。

Output

对于每组数据输出一行,每一行一个数表示答案。

Sample Input

1
10

Sample Output

3

Code

数学(这道题不算是"数论"吧......)

  1. #include<cstring>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<cstdlib>
  7.  
  8. using namespace std;
  9.  
  10. int T;
  11.  
  12. int main()
  13. {
  14. cin>>T;
  15. for(int i=;i<=T;i++)
  16. {
  17. int n,cnt=;
  18. scanf("%d",&n);
  19. n=n-;
  20. for(int i=;i*i<=n;i++)
  21. {
  22. if(n%i==)
  23. cnt+=;
  24. if(i*i==n)
  25. cnt--;
  26. }
  27. printf("%d\n",cnt);
  28. }
  29. return ;
  30. }

数据分割

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description

小w来到百度之星的赛场上,准备开始实现一个程序自动分析系统。
这个程序接受一些形如x_i = x_j 或x_​i​​≠x_​j​​ 的相等/不等约束条件作为输入,判定是否可以通过给每个 w 赋适当的值,来满足这些条件。
输入包含多组数据。 然而粗心的小w不幸地把每组数据之间的分隔符删掉了。 他只知道每组数据都是不可满足的,且若把每组数据的最后一个约束条件去掉,则该组数据是可满足的。
请帮助他恢复这些分隔符。

Input

第1行:一个数字L,表示后面输入的总行数。
之后L行,每行包含三个整数,i,,j,e描述一个相等/不等的约束条件,若e=1,则该约束条件为x_i = x_j若e=0,则该约束条件为x​_i​​!=x_​j​​ 。
i,j,L≤100000
Lx​i​​,x​j​​≤L

Output

输出共T+1行。
第一行一个整数T,表示数据组数。
接下来T行的第i行,一个整数,表示第i组数据中的约束条件个数。

Sample Input

6
2 2 1
2 2 1
1 1 1
3 1 1
1 3 1
1 3 0

Sample Output

1
6

Code

并查集

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<set>
  7.  
  8. #define maxn 200011
  9.  
  10. using namespace std;
  11.  
  12. set<int> s[maxn];
  13.  
  14. int T,n=;
  15. int cnt,vis[maxn],sta[maxn],top;
  16.  
  17. struct Node
  18. {
  19. int fa[maxn];
  20. Node()
  21. {
  22. for(int i=;i<=n;i++)
  23. fa[i]=i;
  24. }
  25. int find(int x)
  26. {
  27. return x==fa[x]?x:(fa[x]=find(fa[x]));
  28. }
  29. void Union(int &x,int &y)
  30. {
  31. x=find(x);
  32. y=find(y);
  33. if(x!=y)
  34. fa[x]=y;
  35. }
  36. }node;
  37.  
  38. int x,y,id;
  39. int ans[maxn];
  40. int lans=,Case;
  41.  
  42. void clear()
  43. {
  44. while (top)
  45. {
  46. int now=sta[top--];
  47. node.fa[now]=now;
  48. s[now].clear();
  49. }
  50. ans[cnt++]=Case;
  51. }
  52.  
  53. int main()
  54. {
  55. scanf("%d",&T);
  56. memset(vis,,sizeof(vis));
  57. top=;
  58. cnt=;
  59. for (Case=;Case<=T;Case++)
  60. {
  61. scanf("%d%d%d",&x,&y,&id);
  62. if(vis[x]!=cnt)
  63. vis[x]=cnt,sta[++top]=x;
  64. if(vis[y]!=cnt)
  65. vis[y]=cnt,sta[++top]=y;
  66. x=node.find(x);
  67. y=node.find(y);
  68. if(s[x].size()>s[y].size())
  69. {
  70. int t=x;
  71. x=y;
  72. y=t;
  73. }
  74. if(id)
  75. {
  76. if(s[x].find(y)!=s[x].end())
  77. {
  78. clear();
  79. continue;
  80. }
  81. node.Union(x,y);
  82. for(set<int>::iterator i=s[x].begin();i!=s[x].end();i++)
  83. {
  84. int now=*i;
  85. now=node.find(now);
  86. s[now].erase(x);
  87. s[y].insert(now);
  88. s[now].insert(y);
  89. }
  90. s[x].clear();
  91. }
  92. else
  93. {
  94. if(x==y)
  95. {
  96. clear();
  97. continue;
  98. }
  99. s[x].insert(y);
  100. s[y].insert(x);
  101. }
  102. }
  103. printf("%d\n",cnt-);
  104. for(int i=;i<cnt;i++)
  105. printf("%d\n",ans[i]-ans[i-]);
  106. return ;
  107. }

路径交

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)

Problem Description

给定一棵n个点的树,以及m条路径,每次询问第L条到第R条路径的交集部分的长度(如果一条边同时出现在2条路径上,那么它属于路径的交集)。

Input

第一行一个数n(n<=500,000)接下来n-1行,每行三个数x,y,z,表示一条从x到y并且长度为z的边第n+1行一个数m(m<=500,000)接下来m行,每行两个数u,v,表示一条从u到v的路径接下来一行一个数Q,表示询问次数(Q<=500,000)接下来Q行,每行两个数L和R

Output

Q行,每行一个数表示答案。

Sample Input

4
1 2 5
2 3 2
1 4 3
2
1 2
3 4
1
1 2

Sample Output

5

Code

线段树区间合并+LCA

  1. #include<cstdlib>
  2. #include<cmath>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<iostream>
  6. #include<algorithm>
  7.  
  8. #define lson x<<1
  9. #define rson x<<1|1
  10.  
  11. using namespace std;
  12.  
  13. const int maxn=;
  14. typedef long long ll;
  15.  
  16. struct path
  17. {
  18. int a,b,c;
  19. path(){}
  20. path(int A,int B,int C)
  21. {
  22. a=A,b=B,c=C;
  23. }
  24. }p[maxn],s[maxn<<];
  25.  
  26. int n,m,q,cnt;
  27. int mn[][maxn<<],Log[maxn<<],pos[maxn],dep[maxn],fa[maxn];
  28. int head[maxn],nxt[maxn<<],val[maxn<<],to[maxn<<];
  29. int cs[];
  30.  
  31. ll len[maxn];
  32.  
  33. int MN(int a,int b)
  34. {
  35. return dep[a]<dep[b]?a:b;
  36. }
  37.  
  38. int lca(int a,int b)
  39. {
  40. int x=pos[a],y=pos[b];
  41. if(x>y)
  42. swap(x,y);
  43. int k=Log[y-x+];
  44. return MN(mn[k][x],mn[k][y-(<<k)+]);
  45. }
  46.  
  47. bool cmp(int a,int b)
  48. {
  49. return dep[a]<dep[b];
  50. }
  51.  
  52. path mix(path x,path y)
  53. {
  54. if(!x.c||!y.c)
  55. return path(,,);
  56. cs[]=lca(x.a,y.a);
  57. cs[]=lca(x.a,y.b);
  58. cs[]=lca(x.b,y.a);
  59. cs[]=lca(x.b,y.b);
  60. sort(cs+,cs+,cmp);
  61. int md=max(dep[x.c],dep[y.c]),nd=min(dep[x.c],dep[y.c]);
  62. if(dep[cs[]]<nd||dep[cs[]]<md)
  63. return path(,,);
  64. else
  65. return path(cs[],cs[],lca(cs[],cs[]));
  66. }
  67.  
  68. inline int read()
  69. {
  70. int ret=,f=;
  71. char gc=getchar();
  72. while(gc<''||gc>''){if(gc=='-')f=-f; gc=getchar();}
  73. while(gc>=''&&gc<='') ret=ret*+gc-'',gc=getchar();
  74. return ret*f;
  75. }
  76.  
  77. void add(int a,int b,int c)
  78. {
  79. to[cnt]=b;
  80. val[cnt]=c;
  81. nxt[cnt]=head[a];
  82. head[a]=cnt++;
  83. }
  84.  
  85. void dfs(int x)
  86. {
  87. pos[x]=++pos[];
  88. mn[][pos[]]=x;
  89. for(int i=head[x];i!=-;i=nxt[i])
  90. {
  91. if(to[i]!=fa[x])
  92. {
  93. fa[to[i]]=x,dep[to[i]]=dep[x]+,len[to[i]]=len[x]+val[i],dfs(to[i]);
  94. mn[][++pos[]]=x;
  95. }
  96. }
  97. }
  98.  
  99. void build(int l,int r,int x)
  100. {
  101. if(l==r)
  102. {
  103. s[x]=p[l];
  104. return ;
  105. }
  106. int mid=l+r>>;
  107. build(l,mid,lson),build(mid+,r,rson);
  108. s[x]=mix(s[lson],s[rson]);
  109. }
  110.  
  111. path query(int l,int r,int x,int a,int b)
  112. {
  113. if(a<=l&&r<=b)
  114. return s[x];
  115. int mid=l+r>>;
  116. if(b<=mid)
  117. return query(l,mid,lson,a,b);
  118. if(a>mid)
  119. return query(mid+,r,rson,a,b);
  120. return mix(query(l,mid,lson,a,b),query(mid+,r,rson,a,b));
  121. }
  122.  
  123. int main()
  124. {
  125. n=read();
  126. int i,j,a,b,c;
  127. memset(head,-,sizeof(head));
  128. for(i=;i<n;i++)
  129. {
  130. a=read(),b=read(),c=read();
  131. add(a,b,c),add(b,a,c);
  132. }
  133. dep[]=;
  134. dfs();
  135. for(i=;i<=*n-;i++)
  136. Log[i]=Log[i>>]+;
  137. for(j=;(<<j)<=*n-;j++)
  138. for(i=;i+(<<j)-<=*n-;i++)
  139. mn[j][i]=MN(mn[j-][i],mn[j-][i+(<<j-)]);
  140. m=read();
  141. for(i=;i<=m;i++)
  142. {
  143. p[i].a=read(),p[i].b=read();
  144. p[i].c=lca(p[i].a,p[i].b);
  145. }
  146. build(,m,);
  147. q=read();
  148. for(i=;i<=q;i++)
  149. {
  150. a=read(),b=read();
  151. path ans=query(,m,,a,b);
  152. printf("%I64d\n",len[ans.a]+len[ans.b]-*len[ans.c]);
  153. }
  154. return ;
  155. }

迷宫出逃

Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 32768/32768 K (Java/Others)

Problem Description

小明又一次陷入了大魔王的迷宫,在无人机的帮忙下,小明获得了整个迷宫的草图。
不同于一般的迷宫,魔王在迷宫里安置了机关,一旦触碰,那么四个方向所在的格子,将翻转其可达性(原先可通过的格子不可通过,反之亦然,机关可以反复触发)。为了防止小明很容易地出逃,魔王在临走前把钥匙丢在了迷宫某处,只有拿到钥匙,小明才能开门在出口处离开迷宫。
万般无奈之下,小明想借助聪明的你,帮忙计算是否有机会离开这个迷宫,最少需要多少时间。(每一单位时间只能向四邻方向走一步)

Input

第一行为 T,表示输入数据组数。
下面 T 组数据,对于每组数据:
第一行是两个数字 n, m(2 < n * m <= 64),表示迷宫的长与宽。
接下来 n 行,每行 m 个字符,‘.’表示空地可以通过,‘x’表示陷阱,‘*’表示机关,‘S’代表起点,‘E’代表出口,‘K’表示钥匙(保证存在且只有一个)。

Output

对第 i 组数据,输出
Case #i:
然后输出一行,仅包含一个整数,表示最少多少步能够拿到钥匙并走出迷魂阵,如果不能则打出-1。

Sample Input

  1.  
  2. ...*x..
  3. ...x...
  4. xEx....
  5. *x...K.
  6. .x*...S
  7.  
  8. K..*x..
  9. ...x...
  10. xEx....
  11. *x.....
  12. .x*...S
  13.  
  14. ..K*x..
  15. ..*x*..
  16. xEx....
  17. *x.....
  18. .x*...S
  19.  
  20. ..K*x..
  21. .*xx*..
  22. *E*....
  23. xx.....
  24. .x*...S
  25.  
  26. S*..
  27. **..
  28. ...E
  29. ...K

View Sample Input

Sample Output

Case #1:
11
Case #2:
13
Case #3:
13
Case #4:
11
Case #5:
-1

Code

状态压缩+BFS

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<queue>
  4. #include<cstring>
  5. #include<vector>
  6.  
  7. typedef unsigned long long LL;
  8.  
  9. using namespace std;
  10.  
  11. int tx[]={-,,,};
  12. int ty[]={,,-,};
  13. int ii=;
  14.  
  15. struct datatype
  16. {
  17. int bs;
  18. LL zt1;
  19. LL zt2;
  20. int x;
  21. int y;
  22. datatype()
  23. {
  24. bs=;
  25. zt1=;
  26. x=;
  27. y=;
  28. zt2=;
  29. }
  30. };
  31. queue<datatype> team;
  32.  
  33. int maps[][];
  34.  
  35. struct mapdata
  36. {
  37. int x,y;
  38. LL zt1;
  39. int zt2;
  40. LL count()
  41. {
  42. LL ans=zt1%;
  43. ans=(ans+zt2)%;
  44. ans=(ans+x)%;
  45. ans=(ans+y)%;
  46. return ans;
  47. }
  48. bool operator<(const mapdata &b)const
  49. {
  50. if(this->x!=b.x)
  51. return this->x<b.x;
  52. if(this->y!=b.y)
  53. return this->y<b.y;
  54. if(this->zt1!=b.zt1)
  55. return this->zt1<b.zt1;
  56. return this->zt2<b.zt2;
  57. }
  58. bool operator==(const mapdata &b)const
  59. {
  60. if(this->x!=b.x)
  61. return this->x == b.x;
  62. if(this->y!=b.y)
  63. return this->y == b.y;
  64. if(this->zt1!=b.zt1)
  65. return this->zt1==b.zt1;
  66. return this->zt2==b.zt2;
  67. }
  68. };
  69.  
  70. char s[][];
  71.  
  72. vector<mapdata> has[];
  73.  
  74. void deal()
  75. {
  76. memset(s,,sizeof(s));
  77. memset(maps,,sizeof(maps));
  78. int n,m;
  79. while(!team.empty())
  80. team.pop();
  81. datatype pt;
  82. cin>>n>>m;
  83. for(int i=;i<=;i++)
  84. has[i].clear();
  85. for(int i=;i<=n;i++)
  86. scanf("%s",s[i]+);
  87. int qdx,qdy;
  88. for(int i=;i<=n;i++)
  89. {
  90. for(int j=;j<=m;j++)
  91. {
  92. if(s[i][j]=='.') maps[i][j]=;
  93. if(s[i][j]=='x') maps[i][j]=;
  94. if(s[i][j]=='E') maps[i][j]=-;
  95. if(s[i][j]=='*') maps[i][j]=-;
  96. if(s[i][j]=='K') maps[i][j]=-;
  97. if(s[i][j]=='S')
  98. {
  99. maps[i][j]=,qdx=i,qdy=j;
  100. pt.bs=,pt.zt1=,pt.zt2=,pt.x=qdx,pt.y=qdy;
  101. team.push(pt);
  102. }
  103. }
  104. }
  105. datatype pd;
  106. int ans=-;
  107. while(!team.empty())
  108. {
  109. pt=team.front();
  110. team.pop();
  111. if(maps[pt.x][pt.y]==-)
  112. {
  113. if(pt.zt2==)
  114. {
  115. ans=pt.bs;
  116. break;
  117. }
  118. }
  119. for(int i=;i<;i++)
  120. {
  121. pd.bs=pt.bs+;
  122. pd.zt1=pt.zt1;
  123. pd.zt2=pt.zt2;
  124. pd.x=pt.x+tx[i];
  125. pd.y=pt.y+ty[i];
  126. if(pd.x<=||pd.y<=||pd.x>n||pd.y>m)
  127. continue;
  128. LL cj=(LL)(m)*(pd.x-)+pd.y;
  129. LL zt=((pd.zt1>>(LL)(cj-))&(LL));
  130. if(zt==&&maps[pd.x][pd.y]==)
  131. continue;
  132. if(zt==)
  133. {
  134. if(maps[pd.x][pd.y] != )
  135. continue;
  136. }
  137. LL ws1,ws2,ws3,ws4;
  138. ws1=;ws2=;ws3=;ws4=;
  139. ws1=(pd.x-)*(m)+pd.y;
  140. ws2=(pd.x)*m+(pd.y);
  141. ws3=(pd.x-)*m+(pd.y-);
  142. ws4=(pd.x-)*m+(pd.y+);
  143. if(maps[pd.x][pd.y]==-)
  144. {
  145. if(pd.x->)
  146. {
  147. if((pd.zt1>>(ws1-(LL)))&(LL))
  148. pd.zt1=pd.zt1-((LL)<<(ws1-(LL)));
  149. else
  150. pd.zt1=pd.zt1+((LL)<<(ws1-(LL)));
  151. }
  152. if(pd.x+<=n)
  153. {
  154. if((pd.zt1>>(ws2-(LL)))&(LL))
  155. pd.zt1=pd.zt1-((LL)<<(ws2-(LL)));
  156. else
  157. pd.zt1=pd.zt1+((LL)<<(ws2-(LL)));
  158. }
  159. if(pd.y->)
  160. {
  161. if((pd.zt1>>(ws3-(LL)))&(LL))
  162. pd.zt1=pd.zt1-((LL)<<(ws3-(LL)));
  163. else
  164. pd.zt1=pd.zt1+((LL)<<(ws3-(LL)));
  165. }
  166. if(pd.y+<=m)
  167. {
  168. if((pd.zt1>>(ws4-(LL)))&(LL))
  169. pd.zt1=pd.zt1-((LL)<<(ws4-(LL)));
  170. else
  171. pd.zt1=pd.zt1+((LL)<<(ws4-(LL)));
  172. }
  173. }
  174. if(maps[pd.x][pd.y]==-)
  175. {
  176. pd.zt2=;
  177. }
  178. mapdata h;
  179. h.x=pd.x;h.y=pd.y;h.zt1=pd.zt1;h.zt2=pd.zt2;
  180. int zzt=h.count();
  181. int vvv=;
  182. for(int k=;k<has[zzt].size();k++)
  183. {
  184. if(has[zzt][k]==h)
  185. {
  186. vvv=;
  187. break;
  188. }
  189. }
  190. if(vvv)
  191. continue;
  192. has[zzt].push_back(h);
  193. team.push(pd);
  194. }
  195. }
  196. printf("Case #%d:\n",ii);
  197. cout<<ans<<endl;
  198. }
  199. int main()
  200. {
  201. int t;
  202. cin>>t;
  203. while(t--)
  204. {
  205. ii++;
  206. deal();
  207. }
  208. return ;
  209. }

今夕何夕

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description

今天是2017年8月6日,农历闰六月十五。
小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。
为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天的星期数一样?比如今天是8月6日,星期日。下一个也是星期日的8月6日发生在2023年。
小贴士:在公历中,能被4整除但不能被100整除,或能被400整除的年份即为闰年。

Input

第一行为T,表示输入数据组数。
每组数据包含一个日期,格式为YYYY-MM-DD。
1 ≤ T ≤ 10000
YYYY ≥ 2017
日期一定是个合法的日期

Output

对每组数据输出答案年份,题目保证答案不会超过四位数。

Sample Input

3
2017-08-06
2017-08-07
2018-01-01

Sample Output

2023
2023
2024

Code

暴力枚举

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. bool isrun(int year)
  12. {
  13. if (year%==&&year%!=||year%==)
  14. return true;
  15. return false;
  16. }
  17.  
  18. int a[][][];
  19. int month[]={,,,,,,,,,,,,};
  20.  
  21. int main()
  22. {
  23. memset(a,-,sizeof(a));
  24. int p=;
  25. for(int year=;year<=;year++)
  26. {
  27. bool run=isrun(year);
  28. for(int m=;m<=;m++)
  29. {
  30. if(run&&m==)
  31. {
  32. for(int d=;d<=month[];d++)
  33. {
  34. a[year][m][d]=p;
  35. p++;
  36. p%=;
  37. }
  38. continue;
  39. }
  40. for(int d=;d<=month[m];d++)
  41. {
  42. a[year][m][d]=p;
  43. p++;
  44. p%=;
  45. }
  46. }
  47. }
  48. int t;
  49. scanf("%d",&t);
  50. while (t--)
  51. {
  52. int y,m,d;
  53. scanf("%d-%d-%d",&y,&m,&d);
  54. for(int i=y+;i<=;i++)
  55. {
  56. if(a[i][m][d]==a[y][m][d])
  57. {
  58. printf("%d\n",i);
  59. break;
  60. }
  61. }
  62. }
  63. return ;
  64. }

度度熊的01世界

Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 32768/32768 K (Java/Others)

Problem Description

度度熊是一个喜欢计算机的孩子,在计算机的世界中,所有事物实际上都只由0和1组成。
现在给你一个n*m的图像,你需要分辨他究竟是0,还是1,或者两者均不是。
图像0的定义:存在1字符且1字符只能是由一个连通块组成,存在且仅存在一个由0字符组成的连通块完全被1所包围。
图像1的定义:存在1字符且1字符只能是由一个连通块组成,不存在任何0字符组成的连通块被1所完全包围。
连通的含义是,只要连续两个方块有公共边,就看做是连通。
完全包围的意思是,该连通块不与边界相接触。

Input

本题包含若干组测试数据。 每组测试数据包含: 第一行两个整数n,m表示图像的长与宽。 接下来n行m列将会是只有01组成的字符画。
满足1<=n,m<=100

Output

如果这个图是1的话,输出1;如果是0的话,输出0,都不是输出-1。

Sample Input

  1.  

View Sample Input

Sample Output

0
1
-1

Code

BFS判连通包含数量

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<queue>
  7.  
  8. #define ms(x,y) memset(x,y,sizeof(x))
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13. const int dx[]={,,,-},dy[]={,,-,};
  14.  
  15. struct node
  16. {
  17. int x, y;
  18. node(int p,int q)
  19. {
  20. x=p;
  21. y=q;
  22. }
  23. };
  24.  
  25. int n,m;
  26. char a[][];
  27. bool book[][];
  28.  
  29. int bfs(int x,int y,char c)
  30. {
  31. int bao=;
  32. queue<node> que;
  33. que.push(node(x,y));
  34. book[x][y]=;
  35. while(que.size())
  36. {
  37. node p=que.front();
  38. que.pop();
  39. for (int i=;i<;i++)
  40. {
  41. int px,py;
  42. px=p.x+dx[i];
  43. py=p.y+dy[i];
  44. if(px>=&&px<n&&py>=&&py<m)
  45. {
  46. if(!book[px][py]&&a[px][py]==c)
  47. {
  48. book[px][py]=;
  49. que.push(node(px,py));
  50. }
  51. }
  52. else
  53. bao=;
  54. }
  55. }
  56. return bao;
  57. }
  58. int main()
  59. {
  60. while(~scanf("%d%d",&n,&m))
  61. {
  62. ms(book,);
  63. ms(a,);
  64. for(int i=;i<n;i++)
  65. {
  66. for(int j=;j<m;j++)
  67. {
  68. scanf(" %c",&a[i][j]);
  69. }
  70. }
  71. int num0=,num1=;
  72. int bao1=,bao0=;
  73. for(int i=;i<n;i++)
  74. {
  75. for(int j=;j<m;j++)
  76. {
  77. if(!book[i][j])
  78. {
  79. if(a[i][j]=='')
  80. {
  81. num0++;
  82. bao1+=bfs(i,j,'');
  83. }
  84. else
  85. {
  86. num1++;
  87. bao0+=bfs(i,j,'');
  88. }
  89. }
  90. }
  91. }
  92. if(num1==&&bao1==)
  93. {
  94. printf("1\n");
  95. }
  96. else if(num1==&&bao1==)
  97. {
  98. printf("0\n");
  99. }
  100. else
  101. printf("-1\n");
  102. }
  103. return ;
  104. }

Time: 2017-08-12

[SinGuLaRiTy] 2017 百度之星程序设计大赛 初赛A的更多相关文章

  1. [SinGuLaRiTy] 2017 百度之星程序设计大赛 初赛B

    [SinGuLaRiTy-1037] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. Chess Time Limit: 2000/1000 ...

  2. HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))

    度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. HDU 6109 数据分割 【并查集+set】 (2017"百度之星"程序设计大赛 - 初赛(A))

    数据分割 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. HDU 6108 小C的倍数问题 【数学】 (2017"百度之星"程序设计大赛 - 初赛(A))

    小C的倍数问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. HDU 6122 今夕何夕 【数学公式】 (2017"百度之星"程序设计大赛 - 初赛(A))

    今夕何夕 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))

    度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. 2017"百度之星"程序设计大赛 - 初赛(A) [ hdu 6108 小C的倍数问题 ] [ hdu 6109 数据分割 ] [ hdu 6110 路径交 ] [ hdu 6112 今夕何夕 ] [ hdu 6113 度度熊的01世界 ]

    这套题体验极差. PROBLEM 1001 - 小C的倍数问题 题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6108 (2017"百度之星 ...

随机推荐

  1. java 删除文件夹 / 删除某文件夹下的所有文件

    import java.io.File; /*************************删除文件夹delFolder / 删除文件夹中的所有文件delAllFile *start******** ...

  2. CRF++评测脚本CoNLL 2000

    关于CRF++工具如何使用这里就不再赘述了,网上相关资源很多,如官方提供的http://crfpp.googlecode.com/svn/trunk/doc/index.html.虽然http://w ...

  3. JAVA简单的文件I/O操作实例

    如果只是对文件进行普通的读写,可以不用文件流. 以下是实例: File file = new File("test1.txt"); //向文件写入数据的 PrintWriter p ...

  4. IdentityHashMap

    区别与其他的键不能重复的容器,IdentityHashMap允许key值重复,但是——key必须是两个不同的对象,即对于k1和k2,当k1==k2时,IdentityHashMap认为两个key相等, ...

  5. Wcf调用方式

    C#动态调用WCF接口,两种方式任你选.   写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去 ...

  6. CSS秘密花园:多边框

    今天在查询CSS3动画相关资料时偶然发现这个,感觉有时还是挺方便的.原文链接:http://www.w3cplus.com/css3/css-secrets/multiple-borders.html ...

  7. elasticsearch2.x线程池配置

    一个Elasticsearch节点会有多个线程池,但重要的是下面四个: 索引(index):主要是索引数据和删除数据操作(默认是cached类型) 搜索(search):主要是获取,统计和搜索操作(默 ...

  8. Python_14-绘图

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  9. 【bzoj2190】[SDOI2008]仪仗队

    2190: [SDOI2008]仪仗队 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2638  Solved: 1674[Submit][Statu ...

  10. 【poj1679】The Unique MST

    [题目大意] 共T组数据,对于每组数据,给你一个n个点,m条边的图,设图的最小生成树为MST,次小生成树为ans,若MST=ans,输出Not Unique!,否则输出MST [题解] 很明确,先求M ...