问题 C: Repeat Number

时间限制: 1 Sec  内存限制: 128 MB

提交: 23  解决: 7

[

cid=1073&pid=2&langmask=0">提交][状态][论坛]

题目描写叙述

Definition: a+b = c, if all the digits of c are same ( c is more than ten)。then we call a and b are Repeat Number. My question is How many Repeat Numbers in [x,y].

输入

There are several test cases.

Each test cases contains two integers x, y(1<=x<=y<=1,000,000) described above.

Proceed to the end of file.

输出

For each test output the number of couple of Repeat Number in one line.

例子输入

1 10 10 12

例子输出

5 2

提示

If a equals b, we can call a, b are Repeat Numbers too, and a is the Repeat Numbers for itself.

这道题,我是暴力加二分过的,枚举c的可能值就可以。然后求中间点与边界差的最小值就可以

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
vector<int> G;
void init()
{
int k=1;
for(int i=0;i<6;i++)
{
k=k*10+1;
for(int j=1;j<=9;j++)
G.push_back(k*j);
}
}
int main()
{
int x,y;
init();
while(cin>>x>>y)
{
int p=lower_bound(G.begin(),G.end(),2*x)-G.begin();
int q=lower_bound(G.begin(),G.end(),2*y)-G.begin();
int ans=0;
//for(int i=0;i<10;i++)
// cout<<G[i]<<endl;
if(G[q]>2*y) q--;
// cout<<p<<" "<<q<<endl;
for(int i=p;i<=q;i++)
{
int mid = G[i]/2;
if (mid* 2 == G[i]) ans += mid-x < y-mid ? mid-x+1 : y-mid+1;
else ans+= mid-x+1 < y-mid ? mid-x+1 : y-mid;
}
cout<<ans<<endl;
}
return 0;
}

2014辽宁省赛 Repeat Number的更多相关文章

  1. Repeat Number

    Problem B: Repeat Number Time Limit: 1 Sec  Memory Limit: 32 MB Description Definition: a+b = c, if ...

  2. 【转】2014区域赛小结(牡丹江&&鞍山)by kuangbin

    Posted on 2014年10月20日 by kuangbin 最后的两场区域赛结束了! ICPC生涯的最后两场区域赛,选择了前两个赛区——牡丹江和鞍山,主要是时间比较靠前,而且我向来对东北赛区有 ...

  3. Repeat Number(数论)

    Repeat Number 题目描述: Definition: a+b = c, if all the digits of c are same ( c is more than ten), then ...

  4. WUSTOJ 1323: Repeat Number(Java)规律统计

    题目链接:1323: Repeat Number Description Definition: a+b = c, if all the digits of c are same ( c is mor ...

  5. NBUT 1223 Friends number 2010辽宁省赛

    Time limit  1000 ms Memory limit   131072 kB Paula and Tai are couple. There are many stories betwee ...

  6. 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)

    题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...

  7. 2015年辽宁省赛Interesting Tree

    题目描述 Recently, Miss Huang want to receive a Tree as her birthday gift! (What a interesting person!)  ...

  8. 13年山东省赛 The number of steps(概率dp水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Me ...

  9. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

随机推荐

  1. HDU1058 Humble Numbers 【数论】

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  2. BZOJ 2588: Spoj 10628. Count on a tree( LCA + 主席树 )

    Orz..跑得还挺快的#10 自从会树链剖分后LCA就没写过倍增了... 这道题用可持久化线段树..点x的线段树表示ROOT到x的这条路径上的权值线段树 ----------------------- ...

  3. hdu1151Air Raid

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  4. urllib模块

    python爬虫-urllib模块   urllib 模块是一个高级的 web 交流库,其核心功能就是模仿web浏览器等客户端,去请求相应的资源,并返回一个类文件对象.urllib 支持各种 web ...

  5. Hadoop: the definitive guide 第三版 拾遗 第十三章 之HBase起步

    指南上这一章的开篇即提出:HBase是一个分布式的.面向列的开源数据库.如果需要实时的随机读/写超大规模数据集,HBase无疑是一个好的选择. 简介 HBase 是一个高可靠性.高性能.面向列.可伸缩 ...

  6. Square:从今天開始抛弃Fragment吧!

    原文链接 : Advocating Against Android Fragments 原文作者 : Pierre-Yves Ricau 译文出自 : 开发技术前线 www.devtf.cn 译者 : ...

  7. QT_opengl_gluPerspective没有定义的处理方法

    原地址:http://blog.sina.com.cn/s/blog_6b11cdda0101fe27.html 例如: gluPerspective( 45.0, (GLfloat)width/(G ...

  8. QT中的pro文件的编写

    原地址:http://blog.csdn.net/fjb2080/article/details/4833666 我们在编译QT的工程的时候,一般都会让qmake自动生成,但有时我们需要定制我们的工程 ...

  9. Delphi 拖放文件编程(覆盖WM_DROPFILES消息)

    unit Unit1; interface usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  ...

  10. PHP之验证码代码

    <?php session_start(); $checkcode=""; /*for($i=0;$i<4;$i++) { $checkcode.=dechex(ran ...