您的位置:首页 > 其它

2017 百度之星 Round 2 - Hdu 6108,6112,6113

2017-08-12 21:01 399 查看
本弱鸡只过了三道水题,最后依靠评测机的卡顿获得了下一轮资格。

还有一题并查集,赛场上没时间写了,有时间补一补。


小C的倍数问题

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

Total Submission(s): 336    Accepted Submission(s): 181


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

 

Source

2017"百度之星"程序设计大赛
- 初赛(A)

列个式子快速发现,只需要求n-1有多少个因子。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn=10555,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L);

int main() {
int cas;
scanf("%d",&cas);
while (cas--) {
int n,i;
scanf("%d",&n);
n--;
int m=sqrt(n),ans=0;
for (i=1;i<=m;i++) {
if (n%i==0) {
if (i*i==n) ans++; else ans+=2;
}
}
printf("%d\n",ans);
}
return 0;
}


今夕何夕

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

Total Submission(s): 870    Accepted Submission(s): 285


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

 

Source

2017"百度之星"程序设计大赛
- 初赛(A)
模拟题。水过

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn=2005,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L);

bool check(int i) {
return (i%4==0&&i%100!=0)||(i%400==0);
}

int main() {
int cas;
scanf("%d",&cas);
while (cas--) {
int i,x,y,d,sum=0;
scanf("%d-%d-%d",&x,&y,&d);
if (check(x)&&y==2&&d==29) {
for (i=x+4;;i+=4) {
sum+=4*365;
if (check(i)) {
sum++;
sum%=7;
} else continue;
if (sum==0) break;
}
} else
for (i=x+1;;i++) {
if (check(i)) {
if (y>2) sum+=366; else sum+=365;
} else if (check(i-1)) {
if (y<=2) sum+=366; else sum+=365;
} else sum+=365;
sum%=7;
if (sum==0) break;
}
printf("%d\n",i);
}
return 0;
}


度度熊的01世界

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

Total Submission(s): 752    Accepted Submission(s): 247


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

32 32
00000000000000000000000000000000
00000000000111111110000000000000
00000000001111111111100000000000
00000000001111111111110000000000
00000000011111111111111000000000
00000000011111100011111000000000
00000000111110000001111000000000
00000000111110000001111100000000
00000000111110000000111110000000
00000001111110000000111110000000
00000001111110000000011111000000
00000001111110000000001111000000
00000001111110000000001111100000
00000001111100000000001111000000
00000001111000000000001111000000
00000001111000000000001111000000
00000001111000000000000111000000
00000000111100000000000111000000
00000000111100000000000111000000
00000000111100000000000111000000
00000001111000000000011110000000
00000001111000000000011110000000
00000000111000000000011110000000
00000000111110000011111110000000
00000000111110001111111100000000
00000000111111111111111000000000
00000000011111111111111000000000
00000000111111111111100000000000
00000000011111111111000000000000
00000000001111111000000000000000
00000000001111100000000000000000
00000000000000000000000000000000
32 32
00000000000000000000000000000000
00000000000000001111110000000000
00000000000000001111111000000000
00000000000000011111111000000000
00000000000000111111111000000000
00000000000000011111111000000000
00000000000000011111111000000000
00000000000000111111110000000000
00000000000000111111100000000000
00000000000001111111100000000000
00000000000001111111110000000000
00000000000001111111110000000000
00000000000001111111100000000000
00000000000011111110000000000000
00000000011111111110000000000000
00000001111111111111000000000000
00000011111111111111000000000000
00000011111111111111000000000000
00000011111111111110000000000000
00000000001111111111000000000000
00000000000000111111000000000000
00000000000001111111000000000000
00000000000111111110000000000000
00000000000011111111000000000000
00000000000011111111000000000000
00000000000011111111100000000000
00000000000011111111100000000000
00000000000000111111110000000000
00000000000000001111111111000000
00000000000000001111111111000000
00000000000000000111111111000000
00000000000000000000000000000000
3 3
101
101
011

 

Sample Output

0
1
-1

dfs一遍,求出1联通块的个数和被1包裹的联通块个数。求完之后直接根据题意判断即可。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn=105,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L);
char s[maxn][maxn];
int a[maxn][maxn];
bool visit[maxn][maxn];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int flag,m,n;

void dfs(int i,int j) {
visit[i][j]=1;
for (int k=0;k<4;k++) {
int x=dir[k][0]+i,y=dir[k][1]+j;
if (x>0&&y>0&&x<=n&&y<=m) {
if (!visit[x][y]&&a[x][y]==1) dfs(x,y);
}
}
}

void dfs0(int i,int j) {
visit[i][j]=1;
for (int k=0;k<4;k++) {
int x=dir[k][0]+i,y=dir[k][1]+j;
if (x>0&&y>0&&x<=n&&y<=m) {
if (!visit[x][y]&&a[x][y]==0) dfs0(x,y);
} else flag=0;
}
}

int main() {
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);
int i,j;
while (scanf("%d%d",&n,&m)!=EOF) {
memset(a,-1,sizeof(a));
for (i=1;i<=n;i++) {
scanf("%s",s[i]+1);
for (j=1;j<=m;j++) {
a[i][j]=s[i][j]-'0';
}
}
int kuai1=0;
mem0(visit);
for (i=1;i<=n;i++) {
for (j=1;j<=m;j++) {
if (a[i][j]==1&&!visit[i][j]) dfs(i,j),kuai1++;
}
}
if (kuai1!=1) {
printf("-1\n");
continue;
}
int kuai0=0,wrap0=0;
for (i=1;i<=n;i++) {
for (j=1;j<=m;j++) {
if (a[i][j]==0&&!visit[i][j]) {
flag=1;
dfs0(i,j),kuai0++;
if (flag) wrap0++;
}
}
}
if (wrap0==1) printf("0\n"); else
if (wrap0==0) printf("1\n"); else printf("-1\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: