heu acm基础训练 1001

哈尔滨工程大学 online judge acm训练之分治算法

原题大意:求a ,b,之间的数有多少个1,包括a,b.

这题典型的分治算法;

举例说明:

以197为例:

那么我们将其分为个位,十位,个位7上有一个,那么在190~197上有7+1个

然后整十位上的为18,即197/10-1,然后其权值将变为10。如此进行。

源代码:

#include<stdio.h>

#define N 11

int d[N],value;

int deal(int n)

{

int one ,ten ;

if(t<=0)

one=n%10;

ten=n/10;

n/=10;

for(int i=0;i<=one;i++)

d[i]+=value;

while(ten)

{

d[ten%10]+=value*(one+1);

ten/=10;

}

for(int i=0;i<N;i++)

d[i]+=value*n;

d[0]-=value;

value*=10;

deal(n-1);

}

int main()

{

int a,b;

while(scanf("%d%d",&a,&b))

{

if(!a,!b)

break;

if(a<b)

swap(a,b);

value=1;

deal(a);

value=-1;

deal(b-1);

printf("%d\n",d[1]);

}

}

d【】中存有0~9的个数,题目的话只用d[1]即可。

时间: 2024-11-08 13:30:25

heu acm基础训练 1001的相关文章

ACM基础训练题解4302 丢失的牛

简单线段树插入和查询删除 1 #include<iostream> 2 #include<cstdlib> 3 #include<cstring> 4 using namespace std; 5 int num[10000]; 6 int node[20000]; 7 int scale; 8 void clear(int n){ 9 scale=1; 10 while(scale<=n+1) 11 scale=scale<<1; 12 memset

ACM基础训练题解4301 城市地平线

遍历线段树   线段树的插入和查询 1 //城市地平线(线段树) 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 #include<cstdio> 7 using namespace std; 8 typedef __int64 LL; 9 struct building{ 10 LL x1; 11 LL x2; 12 LL

武汉科技大学ACM :1001: A+B for Input-Output Practice (I)

Problem Description Your task is to Calculate a + b. Too easy?! Of course! I specially designed the problem for acm beginners.  You must have found that some problems have the same titles with this one, yes, all these problems were designed for the s

武汉科技大学ACM :1001: 零起点学算法34——继续求多项式

Problem Description 输入1个正整数n, 计算1+(1+2)+(1+2+3)+...+(1+2+3+...+n) Input 输入正整数n(多组数据) Output 输出1+(1+2)+(1+2+3)+...+(1+2+3+...+n)的值(每组数据一行) Sample Input 2 Sample Output 4 1 #include<iostream> 2 3 using namespace std; 4 5 int main() 6 7 { 8 9 int n,t;

ACM HDU 1001

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Sum Problem Input The input will consist of a series of integers n, one integer per line. Outp

武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

Problem Description 输入n,输出对应的边长为n的空心正六边形. 为方便看图,样例中点 '.' 表示空格,打印图形时请打印空格而非小圆点. Input 边长n.(n<=20) Output 边长为n的正六边形 Sample Input 5 Sample Output .....***** ....*.....* ...*.......* ..*.........* .*...........* ..*.........* ...*.......* ....*.....* ...

acm入门 杭电1001题 有关溢出的考虑

最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line Output For each case, output SUM(n) in one line

[acm 1001] c++ 大数加法 乘法 幂

北大的ACM 1001 poj.org/problem?id=1001 代码纯手动编写 - - 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 6 class BigNumber 7 { 8 struct BigNumberNode 9 { 10 BigNumberNode():n(0), prev(NULL), next(NULL){} 11 BigNumberNode(int N)

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 208    Accepted Submission(s): 101 Problem Description You may not know this but it's a fact that Xinghai Square is