ACM学习历程—HDU4956 Poor Hanamichi(模拟)
Poor Hanamichi
A integer X can be represented in decimal as: \(X = A_n\times10^n + A_{n-1}\times10^{n-1} + \ldots + A_2\times10^2 + A_1\times10^1 + A_0\) The odd dights are \(A_1, A_3, A_5 \ldots\) and \(A_0, A_2, A_4 \ldots\) are even digits.
Hanamichi comes up with a solution, He notices that: \(10^{2k+1}\) mod 11 = -1 (or 10), \(10^{2k}\) mod 11 = 1, So X mod 11 = \((A_n\times10^n + A_{n-1}\times10^{n-1} + \ldots + A_2\times10^2 + A_1\times10^1 + A_0) \mod 11\) = \(A_n\times(-1)^n + A_{n-1}\times(-1)^{n-1} + \ldots + A_2 - A_1 + A_0\) = sum_of_even_digits – sum_of_odd_digits So he claimed that the answer is the number of numbers X in the range which satisfy the function: X mod 11 = 3. He calculate the answer in this way : Answer = (r + 8) / 11 – (l – 1 + 8) / 11.
Rukaw heard of Hanamichi’s solution from you and he proved there is something wrong with Hanamichi’s solution. So he decided to change the test data so that Hanamichi’s solution can not pass any single test. And he asks you to do that for him.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define INF 0x3fffffff using namespace std; int a[20], len;
long long m, n, ad; void turn(long long m)
{
len = 0;
while (m > 0)
{
a[len++] = m%10;
m /= 10;
}
} void Add()
{
a[0]++;
int i = 0;
while (a[i] >= 10 && i < len-1)
{
a[i+1]++;
a[i] -= 10;
++i;
}
if (a[len-1] >= 10)
{
a[len-1] -= 10;
a[len++] = 1;
}
} bool Ans()
{
int p = 1, ans = 0;
for (int i = 0; i < len; ++i)
{
ans += p*a[i];
p *= -1;
}
if (ans == 3) return 1;
return 0;
} long long judge()
{
int k = 0;
long long l = n - m;
for (int i = 0; i <= l; ++i)
{
k += Ans();
if (k != ((m+i+8)/11) - ((m+7)/11))
{
return m+i;
}
Add();
}
return -1;
} int main()
{
//freopen ("test.txt", "r", stdin);
int T;
scanf ("%d", &T);
for (int times = 0; times < T; ++times)
{
scanf ("%I64d%I64d", &m, &n);
turn(m);
printf ("%I64d\n", judge());
}
return 0;
}
ACM学习历程—HDU4956 Poor Hanamichi(模拟)的更多相关文章
- ACM学习历程—Hihocoder 1177 顺子(模拟 && 排序 && gcd)(hihoCoder挑战赛12)
时间限制:6000ms 单点时限:1000ms 内存限制:256MB 描述 你在赌场里玩梭哈,已经被发了4张牌,现在你想要知道发下一张牌后你得到顺子的概率是多少? 假定赌场使用的是一副牌,四种 ...
- ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- ACM学习历程—ZOJ3878 Convert QWERTY to Dvorak(Hash && 模拟)
Description Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- ACM学习历程—HDU5668 Circle(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5668 这题的话,假设每次报x个,那么可以模拟一遍, 假设第i个出局的是a[i],那么从第i-1个出局的人后,重新 ...
- ACM学习历程—BestCoder Round #75
1001:King's Cake(数论) http://acm.hdu.edu.cn/showproblem.php?pid=5640 这题有点辗转相除的意思.基本没有什么坑点. 代码: #inclu ...
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
- ACM学习历程—HDU2476 String painter(动态规划)
http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意是给定一个起始串和一个目标串,然后每次可以将某一段区间染成一种字符,问从起始串到目标串最少需要染多 ...
随机推荐
- HDU 2242 考研路茫茫——空调教室(边双连通)
HDU 2242 考研路茫茫--空调教室 题目链接 思路:求边双连通分量.然后进行缩点,点权为双连通分支的点权之和,缩点完变成一棵树,然后在树上dfs一遍就能得出答案 代码: #include < ...
- VIM中保存编辑的只读文件
如何在VIM中保存编辑的只读文件 你是否会和我一样经常碰到这样的情景:在VIM中编辑了一个系统配置文件,当需要保存时才发现当前的用户对该文件没有写入的权限.如果已 经做了很多修改,放弃保存的确很懊恼, ...
- implode 函数 把数组拼接成字符串
$array( '0'=>1, '1'=>5, '2'=>5 ); $str=imploade(',',$array); echo str;//输出1,5,3
- MySQL中使用INNER JOIN来实现Intersect并集操作
MySQL中使用INNER JOIN来实现Intersect并集操作 一.业务背景 我们有张表设计例如以下: CREATE TABLE `user_defined_value` ( `RESOURCE ...
- python 基础 7.5 commands 模块
一. commands 模块 1.commands 模块只使用与linxu 的shell 模式下 在我们平时码字时,经常需要调用系统脚本或者系统命令来解决很多问题,接下来,我们就介绍给大家一个很好 ...
- windows下的常用命令
net start ... 启动某个服务 net stop ... 停止某个服务 net start 查看所有启动的服务 services.msc 打开服务的界面 ipconfig ...
- 九度OJ 1049:字符串去特定字符 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8499 解决:3860 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和 ...
- 用CMakeLists.txt组织工程
1 一个工程会有多个CMakeLists.txt,如何组织这些CMakeLists.txt来构建一个工程? 1.1 最外层一个CMakeLists.txt,是总的CMakeList.txt,在这个里 ...
- Swift 学习笔记 (初始化)
初始化是为类 结构体 或者枚举准备实例的过程.这个过程需要给实例里的每一个存储属性设置一个初始值并且在新实例可以使用之前执行任何其它所必需的配置或初始化. 初始化器 初始化器在创建特定类型的实例时被调 ...
- 关于调用notifyDataSetChanged刷新PullToRefreshListView列表无反应解决办法
文章转载自:关于调用notifyDataSetChanged刷新PullToRefreshListView列表无反应解决办法 | TeachCourse