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 题目大意是给定一个起始串和一个目标串,然后每次可以将某一段区间染成一种字符,问从起始串到目标串最少需要染多 ...
随机推荐
- 常用js特效
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.sr ...
- .NET C# Json序列化与反序列化——Newtonsoft.Json学习笔记
Newtonsoft.Json,一款.NET中开源的Json序列化和反序列化类库(介绍及下载地址:http://json.codeplex.com/). /// <summary> ...
- 【demo练习三】:图片水平滚动、点击按钮变更图片动画
要求:四张图片水平滚动,每隔5秒进行一次循环,点击按钮随机变更图片. XAML前台代码: <Window x:Class="图片滚动.MainWindow" xmlns=&q ...
- C#泛型<T>说明
泛型:即通过参数化类型来实现在同一份代码上操作多种数据类型.泛型编程是一种编程范式,它利用“参数化类型”将类型抽象化,从而实现更为灵活的复用. C#泛型的作用概述 C#泛型赋予了代码更强的类型安全,更 ...
- 新西兰天维网登录发送明文password
新西兰比較有人气的华人社区站点是天维网(新西兰天维网),是这边华人用中文吐槽常常上的论坛,也是华人之间各种交易(比方买卖二手车)的集散地.上次非诚勿扰新西兰专场就是天维网承办的宣传和报名.来新西兰定居 ...
- 九度OJ 1175:打牌 (模式匹配)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8156 解决:1560 题目描述: 牌只有1到9,手里拿着已经排好序的牌a,对方出牌b,用程序判断手中牌是否能够压过对方出牌. 规则:出牌 ...
- There are two different types of export, named and default
export - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statemen ...
- 2017-2018-1 20179209《Linux内核原理与分析》第四周作业
本周学习内容为<跟踪分析MenuOS简单linux系统的启动过程>和教材中的进程调度及内核数据结构. 一.跟踪分析Linux内核的启动过程 这个实验我是在实验楼环境中完成的,最初想在自己的 ...
- python cookbook第三版学习笔记十三:类和对象(四)描述器
__get__以及__set__:假设T是一个类,t是他的实例,d是它的一个描述器属性.读取属性的时候T.d返回的是d.__get__(None,T),t.d返回的是d.__get__(t,T).说法 ...
- cordova 实现拨打电话-只需两步(H5)
cordova 实现拨打电话: 第一步配置conf.xml在cordova中所有的URL Schemes 都是服从于白名单的,所以a tel 在这无法正常使用.解决方法是在项目config.xml中添 ...