ACM学习历程—BestCoder Round #75
1001:King's Cake(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5640
这题有点辗转相除的意思。基本没有什么坑点。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; int n, m; int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
scanf("%d%d", &n, &m);
int ans = ;
while (n&&m)
{
if (n > m) swap(n, m);
ans += m/n;
m = m%n;
}
printf("%d\n", ans);
}
return ;
}
1002:King's Phone(模拟)
http://acm.hdu.edu.cn/showproblem.php?pid=5641
这题坑点有点多,3A。。首先任意一条连线,需要判断中间有没有经过什么点。
然后不能有重复的点,需要判断。
其次,对于0和大于9的数据需要判断掉。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; int k, s[];
bool vis[]; int cross(int from, int to)
{
if (from > to) swap(from, to);
if (from == && to == ) return ;
if (from == && to == ) return ;
if (from == && to == ) return ;
if (from == && to == ) return ;
if (from == && to == ) return ;
if (from == && to == ) return ;
if (from == && to == ) return ;
if (from == && to == ) return ;
return ;
} bool work()
{
if (k < ) return false;
memset(vis, false, sizeof(vis));
int t;
for (int i = ; i < k; ++i)
{
if (s[i-] == || s[i] == ) return false;
if (s[i-] > || s[i] > ) return false;
if (s[i] == s[i-]) return false;
if (vis[s[i]]) return false;
t = cross(s[i-], s[i]);
if (t && !vis[t]) return false;
vis[s[i-]] = true;
vis[s[i]] = true;
}
return true;
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
scanf("%d", &k);
for (int i = ; i < k; ++i)
scanf("%d", &s[i]);
if (work()) printf("valid\n");
else printf("invalid\n");
}
return ;
}
1003:King's Order(递推)
http://acm.hdu.edu.cn/showproblem.php?pid=5642
这题是个递推,但是没考虑清楚,递推式一直是错的,4A。。
设p[n][k]表示n长度字符串,结尾k个相同的情况数。
那么:
p[i][1] = 25*(p[i-1][1]+p[i-1][2]+p[i-1][3])%MOD;
p[i][2] = p[i-1][1];
p[i][3] = p[i-1][2];
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long
#define MOD 1000000007 using namespace std; const int maxN = ;
int n;
LL p[maxN][]; void init()
{
p[][] = ;
p[][] = ;
p[][] = ;
for (int i = ; i < maxN; ++i)
{
p[i][] = *(p[i-][]+p[i-][]+p[i-][])%MOD;
p[i][] = p[i-][];
p[i][] = p[i-][];
}
} int main()
{
//freopen("test.in", "r", stdin);
init();
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
scanf("%d", &n);
cout << (p[n][]+p[n][]+p[n][])%MOD << endl;
}
return ;
}
1004:King's Game(递推)
http://acm.hdu.edu.cn/showproblem.php?pid=5643
这一题想法类似于O(n)做法的约瑟夫问题。需要考虑子问题,然后映射回来。具体的方法百度百科里有。
最后
p(n, k) = (p(n-1, k+1)+k)%n or n(if 0)
不过我二逼的离线了一发,然后MLE了。。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; const int maxN = ;
/*
int p[maxN][maxN]; void init()
{
for (int i = 0; i < maxN; ++i)
p[1][i] = 1;
for (int i = 2; i < maxN; ++i)
{
for (int j = 1; j < maxN; ++j)
{
p[i][j] = (p[i-1][j+1]+j)%i;
if (!p[i][j]) p[i][j] = i;
}
}
}
*/ int dfs(int n, int k)
{
if (n == ) return ;
int ans;
ans = (dfs(n-, k+)+k)%n;
if (!ans) ans = n;
return ans;
} int main()
{
//freopen("test.in", "r", stdin);
//init();
int n, T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
scanf("%d", &n);
printf("%d\n",dfs(n, ));
}
return ;
}
1005:没有想法。。应该是水平还没到火候。。。
ACM学习历程—BestCoder Round #75的更多相关文章
- ACM学习历程—Codeforces Round #354 (Div. 2)
http://codeforces.com/contest/676 在allzysyz学弟和hqwhqwhq的邀请下,打了我的第三场CF... 毕竟在半夜..所以本来想水到12点就去睡觉的...结果一 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1006 单调区间(组合数学)
Problem Description 百小度最近在逛博客,然后发现了一个有趣的问题. 如下图所示,是一个12 位数014326951987 , 它的数字先逐渐变大, 然后变小,再变大,接着变小,又变 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1004 放盘子(策略 && 计算几何)
Problem Description 小度熊喜欢恶作剧.今天他向来访者们提出一个恶俗的游戏.他和来访者们轮流往一个正多边形内放盘子.最后放盘子的是获胜者,会赢得失败者的一个吻.玩了两次以后,小度熊发 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1001 大搬家(递推 && 组合数学)
Problem Description 近期B厂组织了一次大搬家,所有人都要按照指示换到指定的座位上.指示的内容是坐在位置i 上的人要搬到位置j 上.现在B厂有N 个人,一对一到N 个位置上.搬家之后 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1002 列变位法解密(vector容器)
Problem Description 列变位法是古典密码算法中变位加密的一种方法,具体过程如下 将明文字符分割成个数固定的分组(如5个一组,5即为密钥),按一组一行的次序整齐排列,最后不足一组不放置 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1003 IP聚合(set容器)
Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网 ...
- BestCoder Round #75 1001 - King's Cake
Problem Description It is the king's birthday before the military parade . The ministers prepared a ...
- hdu 5643 BestCoder Round #75
King's Game Accepts: 249 Submissions: 671 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6 ...
- hdu 5641 BestCoder Round #75
King's Phone Accepts: 310 Submissions: 2980 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- python 可变参数函数定义* args和**kwargs的用法
python函数可变参数 (Variable Argument) 的方法:使用*args和**kwargs语法.其中,*args是可变的positional arguments列表,**kwargs是 ...
- php修改密码
为了让页面更为好看一些,我一般会选择bootstrap,写起来虽然看着麻烦,但是我们真正需要的只有中间的内容 下面是html的内容 <div id="tbx"" ...
- Jmeter+Ant+Jenkins接口自动化测试框架搭建
前言 软件开发的V模型大家都不陌生,其中测试阶段分为单元测试→功能测试→系统测试→验收测试.其中单元测试一般由开发同学们自己完成,大部分测试具体实施(这里不包括用例设计)是从单体功能测试开始着手的. ...
- 【BZOJ3720】Gty的妹子树 块状树
[BZOJ3720]Gty的妹子树 我曾在弦歌之中听过你,檀板声碎,半出折子戏.舞榭歌台被风吹去,岁月深处尚有余音一缕……Gty神(xian)犇(chong)从来不缺妹子……他来到了一棵妹子树下,发现 ...
- elasticsearch从入门到出门-03-多种搜索
1.query string search 2.query DSL 3.query filter 4.full-text search 5.phrase search 6.highlight sear ...
- java 分布式锁 -图解- 秒懂
目录 写在前面 1.1. 分布式锁 简介 1.1.1. 图解:公平锁和可重入锁 模型 1.1.2. 图解: zookeeper分布式锁的原理 1.1.3. 分布式锁的基本流程 1.1.4. 加锁的实现 ...
- LOJ#10064. 「一本通 3.1 例 1」黑暗城堡
LOJ#10064. 「一本通 3.1 例 1」黑暗城堡 题目描述 你知道黑暗城堡有$N$个房间,$M$条可以制造的双向通道,以及每条通道的长度. 城堡是树形的并且满足下面的条件: 设$D_i$为如果 ...
- mysql 分页测试,
大环境:MySQL5.6 自己造了 27万数据, 一次性 查出来,会超时: 而分页跑,会查出来8s: 但是在少于27万时,直接查比 分页查快5倍:
- 图形数据库(GraphDB)
Date: 2016-01-27 Title: 图形数据库-1 Published: true Type: post Excerpt: Category: GraphDB 图形数据库(GraphDB) ...
- 第2条:遵循PEP8风格指南
<Python Enhancement Proposal #8>(8号Python增强提案)又叫PEP8,它是针对Python代码格式而编订的风格指南. 尽管可以在保证语法正确的前提下随意 ...