*HDU 2451 数学

Simple Addition Expression

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1723    Accepted Submission(s): 675

Problem Description

A
luxury yacht with 100 passengers on board is sailing on the sea in the
twilight. The yacht is ablaze with lights and there comes out laughers
and singing from the hall where an evening party is in full swing.
People are singing, dancing and enjoying themselves.

The yacht is
equipped with the most advanced navigation and driving system which can
all be manipulated by a computer. When the captain notices that there
is only gentle breeze and the sea waves are not high, he starts the
autopilot. The yacht sails forward smoothly, ploughs the waves. When
it’s completely dark, the passengers start to feel a little funny for
sudden forward rushes or sudden decelerations or slight swings. The
captain immediately walks to the driving platform and switches the
autopilot to human manipulation. The yacht returns back to normal and
the party restarts. Laughers come back, too.

The captain summons
the engineer on board to do a thorough check of the navigation system.
It turns out that only the computer is out of order, but the exact
failure is still unclear. There is a computer scientist among the
passengers who is also invited to the cab to give a hand. He first
inputs several groups of data to test the computer. When he inputs
1+2+3, the computer outputs 6, which is exactly right. But when he
inputs 4+5+6, the computer outputs 5, which is wrong. Then he inputs
12+13+14, and gets 39, another right answer, while he inputs 14+15+16,
and gets 35, another wrong answer. After the test, the computer
scientist says smilingly: “the failure is clear now. The computer‘s
adder can not carry." After excluding the failure, the captain restarts
the autopilot and the yacht returns back to normal, sailing smoothly on
the sea.

The captain and the engineer invite the computer
scientist to sit down and have a talk. The computer scientist tells a
story as following:

A former mathematician defined a kind of simple addition expression.
If
there is an expression (i) + (i+1) + (i+2), i>=0, when carried out
additive operations, no position has a carry, it is called simple
addition expression.

For instance, when i equals 0, 0+1+2 is a
simple addition expression, meanwhile when i equals 11, 11+12+13 is a
simple addition expression, too. Because of that no position has a
carry.

However, when i equals 3, 3+4+5 is not a simple addition
expression, that is because 3+4+5 equals 12, there is a carried number
from unit digit to tens digit. In the same way, when i equals 13,
13+14+15 is not a simple addition expression, either. However, when i
equals 112, 112+113+114 is a simple addition expression. Because
112+113+114 equals 339, there is no carry in the process of adding.

when
the students have got the definition of simple addition expression, the
mathematician puts forward a new question: for a positive integer n,
how many simple addition expressions exist when i<n. In addition, i
is the first number of a simple addition expression.

when the value of n is large enough, the problem needs to be solved by means of computer.

Input

There are several test cases, each case takes up a line, there is an integer n (n<10^10).

Output

Output the number of all simple addition expressions when i<n.

Sample Input

1
2
3
4
10
11

Sample Output

1
2
3
3
3
4

Source

2008 Asia Regional Harbin

题意:

问小于n的数i中i+i+1+i+2不会产生进位的i有多少个。

代码:

 1 //最近一段时间被数学搞晕了,各种烦躁,迷糊。这道题可以把数拆开来,首位可以取1,2,3,中间可以取0,1,2,3,最后一位可以取0,1,2。有多少个i,比如拆2345,
 2 //先计算0~999有多少个,再计算1000~1999有多少个,再计算2000上面0~99,100~199,200~299有多少个,再计算300上面........如果第一位大于3,比如4321,那么他
 3 //和9999没什么区别,中间的几位也是同样的道理。
 4 #include<bits\stdc++.h>
 5 #define ll long long
 6 using namespace std;
 7 char s[12];
 8 ll f[12];
 9 int main()
10 {
11     f[0]=0;f[1]=3; //10以下的有几个,下面的同理
12     for(int i=2;i<=11;i++)
13     {
14         f[i]=4*f[i-1];
15     }
16     while(scanf("%s",s)!=EOF)
17     {
18         ll ans=0;
19         int len=strlen(s);
20         for(int i=0;i<len;i++)
21         {
22             if(i==0&&i!=len-1)
23             {
24                 if(s[i]-‘0‘>3)
25                 {ans+=f[len-i];break;}
26                 else ans+=(s[i]-‘0‘)*f[len-i-1];
27             }
28             else if(i!=0&&i!=len-1)
29             {
30                 if(s[i]-‘0‘>3)
31                 {ans+=f[len-i];break;}
32                 else ans+=(s[i]-‘0‘)*f[len-i-1];
33             }
34             else if(i==len-1)
35             ans+=s[i]-‘0‘>3?3:s[i]-‘0‘;
36         }
37         printf("%lld\n",ans);
38     }
39     return 0;
40 }
时间: 2024-12-30 03:11:33

*HDU 2451 数学的相关文章

hdu 4961 数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=4961 先贴个O(nsqrtn)求1-n所有数的所有约数的代码: vector<int>divs[MAXN]; void caldivs() { for(int i=1;i<MAXN;i++) for(int j=i;j<MAXN;j+=i) divs[j].push_back(i); } 有了这个当时理下思路就可写了,但是重复数处理注意: 1.用一个数组vis[]  vis[i]=1表示i存在

HDU 2451 Simple Addition Expression(组合数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laughers and singing from the hall where an

HDU 5976 数学,逆元

1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更大(当然不能拆1).所以容易想到是拆成2+3+...+n+s=x,先求出n即2+3+...+n<x<2+3+...+n+(n+1),然后将某个数向右平移s个单位变为n+1即可.注意:(1)预处理出前缀和,前缀积.(2)将某个数移到n+1,要除这个数再乘n+1,这里要用逆元,也要预处理出来. #in

hdu 4811 数学 不难

http://acm.hdu.edu.cn/showproblem.php?pid=4811 因为看到ball[0]>=2 && ball[1]>=2 && ball[2]>=2  ans=(sum-6)*6+15    sum是三种颜色的球个数的和,然后就想到分类讨论,因为情况是可枚举的, 发现整数如果不加LL直接用%I64d打印会出问题 //#pragma comment(linker, "/STACK:102400000,102400000

[ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了一发没过 上网看了一下才知道是快速幂 而且特征方程的推导简直精妙 尤其是共轭相抵消的构造 真的是太看能力了 (下图转自某大神博客) 特征方程是C^2=-2*a*C+(a*a-b) 然后用快速幂求解 临时学了下矩阵快速幂 从这道题能看出来 弄ACM真的要数学好 这不是学校认知的高数 线代 概率分数 而

hdu 4506(数学,循环节+快速幂)

小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 5427    Accepted Submission(s): 1461 Problem Description 小明自从告别了ACM/ICPC之后,就开始潜心研究数学问题了,一则可以为接下来的考研做准备,再者可以借此机会帮助一些同学,尤其是漂亮的师妹.这 不,班

hdu 5399(数学推理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5399: 题意: 给你m个函数f1,f2,?,fm:{1,2,?,n}→{1,2,?,n}(即所有的x∈{1,2,?,n},对应的f(x)∈{1,2,?,n}),已知其中一部分函数的函数值,问你有多少种不同的组合使得所有的i(1≤i≤n),满足f1(f2(?fm(i)))=i 对于函数集f1,f2,?,fm and g1,g2,?,gm,当且仅当存在一个i(1≤i≤m),j(1≤j≤n),fi(j)≠

hdu 4432 数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=4432 6分钟写的代码,一上午去调试,, 哎,一则题目没看懂就去写了,二则,哎,,恶心了,在坚持几天然后ACM退役,想当初一直想着regional拿奖,然后在保研的时候有个更漂亮的简历,卧槽,但是,其实喜欢的是静下心,把一块知识好好弄懂,看着自己一点点由不会到会,由不熟到熟练,而且在这个过程中总结一些思考问题的方法,能把这种思维应用于其他 但是----唉,急功近利式地学,老想着快,一没思路就去看题解,然后平均每

hdu 3573(数学+贪心)

Buy Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 868    Accepted Submission(s): 392 Problem Description Imyourgod need 3 kinds of sticks which have different sizes: 20cm, 28cm and 32cm