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. 使用MYCAT轻松实现MYSQL水平分片

    完整文章下载地址:http://download.csdn.net/detail/dreamcode/9383516 简单来说,我们能够将数据的水平切分理解为是依照数据行的切分.就是将表中的某些行切分 ...

  2. Unity 插件收集(持续更新)

    MGS Machinery Unity绑定机械关节,铰链,机构插件包.    MGS Mechanical Drive 用于绑定场景中的机械驱动器的Unity插件   Unity Wave Propa ...

  3. MySQL 数据库事物隔离级别的设置

    select @@tx_isolation; //查看隔离级别 set session transaction isolation level read uncommitted; //设置读未提交级别 ...

  4. Java语言平台

    J2SE(Java 2 Platform Standard Edition) 标准版 开发普通桌面和商务应用程序提供的解决方案,该技术体系是下面两者的基础,可以完成一些桌面应用程序的开发 J2ME(J ...

  5. linux 4 -awk

    十一.  awk编程:     1.  变量:     在awk中变量无须定义即可使用,变量在赋值时即已经完成了定义.变量的类型可以是数字.字符串.根据使用的不同,未初始化变量的值为0或空白字符串&q ...

  6. python多版本管理

    1.查看系统中的安装了那些python版本 2.查看系统中的alternatives命令是否安装 3.使用alternatives --install 接管python -install 选项使用了多 ...

  7. C#访问数据库的步骤

    1.必须导入包含适当的ADO.NET类的名称空间 2.获取具体的数据库连接字符串. 3.实例化Connection对象,并建立.打开连接. 4.使用Command对象,从数据库存取器中读取数据和向数据 ...

  8. 全自动安装mongoDB数据库的shell脚本

    最近在研究mongoDB数据库,写了个全自动安装mongoDB数据库的shell脚本,仅供参考,欢迎拍砖,内容如下: #!/bin/bash # shell的执行选项: # -n 只读取shell脚本 ...

  9. GUI菜单——菜单条、菜单、子条目之间关系

    菜单:注意区分三个概念:菜单条.菜单.菜单项 将菜单条添加到窗体,菜单条下面包括菜单,菜单下面可以使菜单或者菜单项 菜单项是最后一个.菜单后面有三角标示. 菜单条[文件] 子菜单--子条目 子条目 示 ...

  10. Data Structure Binary Tree: Morris traversal for Preorder

    http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...