POJ-2282-The Counting Problem
来源:互联网 发布:搜谱网 心事谁人知 编辑:程序博客网 时间:2024/05/29 17:48
本来是个搜索题,但是发现用数学的方法做的,队友讲的
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;int n,m,ansa[11],ansb[11];void GetNum(int num,int *ans){ for(int i=1;i<=9;i++) {int x=num,index=10,now=10;int sum=x/10;if(i<=x%10) sum++;while(x){ if(index*10>x) {if(i==x/index%10) sum+=x%index+1;else if(i<x/index%10) sum+=now;break; } if(i<x/index%10)sum+=(x/index/10+1)*now; elsesum+=(x/index/10)*now; if(i==x/index%10)sum+=x%index+1; now*=10; index*=10;}ans[i]=sum; } int i=1,k=0,r; int x=num; while(x>=10) {r=x%10;x/=10;if(r) ans[0]+=i*x;else ans[0]+=(x-1)*i+k+1;k+=r*i;i*=10; }}int main(){ while(scanf("%d%d",&n,&m)&&(n+m)) {memset(ansa,0,sizeof(ansa));memset(ansb,0,sizeof(ansb));if(n>m) swap(n,m);n--;GetNum(m,ansb);GetNum(n,ansa);printf("%d",ansb[0]-ansa[0]);for(int i=1;i<10;i++) printf(" %d",ansb[i]-ansa[i]);printf("\n"); } return 0;}
- poj 2282 The Counting Problem
- POJ-2282-The Counting Problem
- [POJ] 2282 -> The Counting Problem
- POJ 2282 The Counting Problem
- POJ 2282 The Counting Problem
- POJ 2282 The Counting Problem,组合数学
- The Counting Problem - POJ 2282 数位dp
- POJ题目2282 The Counting Problem(数学)
- poj 2282 The Counting Problem 按位统计
- POJ 2282-The Counting Problem(组合数学_区间计数)
- POJ 2282 && HDU 1663 The Counting Problem(数论)
- POJ 2282 The Counting Problem (数位dp)
- poj 2282 The Counting Problem (数位DP)
- BZOJ 1833 & POJ 2282 The Counting Problem & huangyueying 贪心详解
- pku 2282 The Counting Problem
- 统计区间[a,b]各个数字出现的个数:poj 2282 The Counting Problem poj 3286
- POJ 2282 The Counting Problem & POJ 3286 How many 0's?(按位计算贡献)
- poj 2282 The Counting Problem && poj 3286 How many 0's? (数位dp)
- 高级Bash脚本编程指南(32):混杂命令(一)
- 内核中的UDP socket流程(6)——sendto
- 跟我一起学写jQuery插件开发方法
- 高性能I/O设计模式Reactor和Proactor
- 最小生成树
- POJ-2282-The Counting Problem
- delphi使用回车设置焦点改变
- 进程和线程的区别
- quake 3场景源码分析
- 工作邮件回复说明
- 搜狗地图刷新后可拖动的小红点不更新
- 求带走!!应届毕业生艰难的找工作历程!
- @Transactional的用法
- 编写一个单文档界面应用程序,该程序可以测试在鼠标左键按下时鼠标光标的位置是否处在某规定的矩形框内,如果不在该矩形内则计算机的扬声器会发出“叮”的声音,反之则会在用户区显示光标的位置。