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的更多相关文章

  1. ACM学习历程—Codeforces Round #354 (Div. 2)

    http://codeforces.com/contest/676 在allzysyz学弟和hqwhqwhq的邀请下,打了我的第三场CF... 毕竟在半夜..所以本来想水到12点就去睡觉的...结果一 ...

  2. ACM学习历程—BestCoder 2015百度之星资格赛1006 单调区间(组合数学)

    Problem Description 百小度最近在逛博客,然后发现了一个有趣的问题. 如下图所示,是一个12 位数014326951987 , 它的数字先逐渐变大, 然后变小,再变大,接着变小,又变 ...

  3. ACM学习历程—BestCoder 2015百度之星资格赛1004 放盘子(策略 && 计算几何)

    Problem Description 小度熊喜欢恶作剧.今天他向来访者们提出一个恶俗的游戏.他和来访者们轮流往一个正多边形内放盘子.最后放盘子的是获胜者,会赢得失败者的一个吻.玩了两次以后,小度熊发 ...

  4. ACM学习历程—BestCoder 2015百度之星资格赛1001 大搬家(递推 && 组合数学)

    Problem Description 近期B厂组织了一次大搬家,所有人都要按照指示换到指定的座位上.指示的内容是坐在位置i 上的人要搬到位置j 上.现在B厂有N 个人,一对一到N 个位置上.搬家之后 ...

  5. ACM学习历程—BestCoder 2015百度之星资格赛1002 列变位法解密(vector容器)

    Problem Description 列变位法是古典密码算法中变位加密的一种方法,具体过程如下 将明文字符分割成个数固定的分组(如5个一组,5即为密钥),按一组一行的次序整齐排列,最后不足一组不放置 ...

  6. ACM学习历程—BestCoder 2015百度之星资格赛1003 IP聚合(set容器)

    Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网 ...

  7. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  8. hdu 5643 BestCoder Round #75

    King's Game  Accepts: 249  Submissions: 671  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6 ...

  9. hdu 5641 BestCoder Round #75

    King's Phone  Accepts: 310  Submissions: 2980  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. POJ 1860

    须要推断是否有正权环存在,Bellman-Ford算法就能够辣~ AC代码: #include <iostream> #include <cstdio> #include &l ...

  2. Android 一个强大的图片选择器

    看看下面的图片选择器,感觉很不错 http://www.jcodecraeer.com/a/anzhuokaifa/2017/0122/7083.html 看看下面的图片选择器,支持视频等 http: ...

  3. EasyPlayer.js H5播放器帮助我这种不会前端的普通用户也能轻松实现直播接入

    说到EasyPlayer.js,先得说一下EasyPlayer到底是啥, An elegant, simple, fast android RTSP/RTMP/HLS/HTTP Player.Easy ...

  4. 宇视摄像机/NVR OCX插件插件安装出现:Failed to register ocx, error code 14001 错误的解决方法

    最近在使用EasyNVR接入海康.宇视的摄像机进行景观直播的项目时,需要进入宇视设备进行音视频编码参数的调整,要说呢,海康的产品好就是要好很多: 海康的设备后台管理页面,不需要装插件也能进去,而且能调 ...

  5. linux下jdk多版本管理

    linux下jdk多版本管理 项目开发中,不管是哪种语言都避免不了多个版本环境管理问题(本文虽然以jdk为例来写的,但不仅限于jdk),如何能做到快速的环境升级与切换确实是一件深思的事! 安装jdk ...

  6. 记录-在jsp页面获取后台值在页面显示过长处理

    在下面的红色标记处 后台获取的值(字符串)在页面显示过长或者与其他重叠 (xxx).cutStr(15) 15代表的是展示字符串的长度 data.rows[i].avgPrice, ), data.r ...

  7. java堆分析神器MAT

    Memory Analyzer(MAT) 基于Eclipse的软件 http://www.eclipse.org/mat/

  8. Django 基于Ajax & form 简单实现文件上传

    前端实现 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="U ...

  9. vue 指令系统的使用

    所谓指令系统,大家可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了. 在vue中,指令系统,设置一些命令之后,来操作我们的数据属性,并展示到我们的DOM上. OK,接下来我们 ...

  10. eclilpse svn : Item is out of date 解决办法

    尝试以下方面, 1. 2.如果上面的还不行,就说明你修改了原有项目结构,可能是增加了新包,或者重命名的包或文件,那么你得先update,然后再提交 这样就OK了,我就是用了2才成功的哦.