poj——1019(数学)
来源:互联网 发布:传智播客php笔记 编辑:程序博客网 时间:2024/05/16 13:39
题目地址:http://poj.org/problem?id=1019
小结:看到网上许多题解都是找规律的,其实不找规律也是可以做的。如下:
#include <iostream>#include <cmath>#include <string>#include <cstring>#include <cstdlib>#include <ctime>#include <algorithm>#include <cstdio>using namespace std;typedef long long ll;#define INF 0x7fffffff#define MAX(a,b) a>b?a:b#define MIN(a,b) a>b?b:a#define N 50000ll a[N];int q;void init(){int i;a[0]=0;for(i=1;i<N;i++){ //以i为结束所表示的范围, if(i<10) a[i]=a[i-1]+i;else if(i<100) a[i]=a[i-1]+i*2-9;else if(i<1000) a[i]=a[i-1]+i*3-108;else if(i<10000) a[i]=a[i-1]+i*4-1107;else if(i<100000) a[i]=a[i-1]+i*5-11106;if(a[i]>(ll)INF) break; }q=i;}int resolve(int n){int i;for(i=1;i<=q;i++){if(n>a[i-1]&&n<=a[i]) break; //找到n所在的段,然后再在段里面找 }int temp=n-a[i-1];if(temp<10) return temp;temp-=9;for(i=10;i<=q;i++){if(i<100) {if(temp<=2) break; temp-=2;}else if(i<1000) {if(temp<=3) break; temp-=3;}else if(i<10000){if(temp<=4) break;temp-=4;}else if(i<100000){if(temp<=5) break;temp-=5;}}int p=0,digite[10];while(i){digite[p++]=i%10;i/=10;}return digite[p-temp];}int main(){int i,j,k,t;int m,n;init();cin>>t; while(t--) { cin>>n; printf("%d\n",resolve(n)); }return 0;}
- poj——1019(数学)
- POJ——2249(组合数学)
- poj——1833(组合数学之排列数)
- POJ 1019 Number Sequence(组合数学)
- POj 1019 number sequence(数学)
- POJ-1019-数学规律
- POJ 1019 数学
- poj 1019 (数学计算)
- 组合数学——POJ 3088
- 题目推荐—POJ数学题目
- POJ数学(ZZ)
- poj 1840 (数学)
- POJ 2853 (数学)
- POJ 1019 数学找规律
- poj 1019 Number Sequence 数学
- POJ 2140(数学问题)
- POJ 3737 UmBasketella (数学)
- poj 3196(水数学)
- poj 2411 Mondriaan's Dream(状态压缩DP)
- 变更控制流程图(PMP第五版)
- windows编程模型
- J.U.C包介绍
- POJ 2245 Lotto (枚举)
- poj——1019(数学)
- 关于C/C++函数指针声明的理解
- Steve Yegge:Google面试秘籍
- build/core/base_rules.mk:195: already define
- URAL 1635
- 分类算法之决策树
- Linux内核高端内存
- asp.net WebForm程序删除.designer.cs文件,重新设计并绑定服务端控件时间
- Ural 1397. Points Game