暴力枚举
2014-05-19 12:59
253 查看
ZOJ1095
这题只要枚举出2^i * 3^j *5^k *7^l 即可,最后排序
ZOJ1110
ZOJ1110简单题
暴力枚举 写好约束条件集合
sp>=pu+s;
pu>=ye+p;
sp>=ye+p;
推出:
0<=ye<=(12+j-max(s+p,y)-p)/2;
ye+p<=pu<=sp-s;
max(s+p,y)<=sp<=12+j;
时间限制: 1 Sec 内存限制: 32 MB
提交: 63 解决: 26
[提交][状态][讨论版]
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.
If a equals b, we can call a, b are Repeat Numbers too, and a is the Repeat Numbers for itself.
先打表出所有的repeat number再暴力 出x,y的组合个数
这题只要枚举出2^i * 3^j *5^k *7^l 即可,最后排序
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const long long N= 2000000000; void get(int n) { if(n%100==11||n%100==12||n%100==13)printf("th"); else if(n%10==1)printf("st"); else if(n%10==2)printf("nd"); else if(n%10==3)printf("rd"); else printf("th"); } int main() { long long i,j,k,l,m,p=1; long long a[6000]; for(i=1;i<N;i*=2) { for(j=1;j<N;j*=3) { if(i*j>N)break; for(k=1;k<N;k*=5) { if(i*j*k>N)break; for(l=1;l<N;l*=7) { if((m=i*j*k*l)>N)break; a[p++]=m; } } } } sort(a+1,a+5843); int n; while(~scanf("%d",&n)&&n){ printf("The %d",n); get(n); printf(" humble number is %d.\n",a ); } return 0; }
ZOJ1110
ZOJ1110简单题
暴力枚举 写好约束条件集合
sp>=pu+s;
pu>=ye+p;
sp>=ye+p;
推出:
0<=ye<=(12+j-max(s+p,y)-p)/2;
ye+p<=pu<=sp-s;
max(s+p,y)<=sp<=12+j;
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define N 100 using namespace std; int ans; int s,p,y,m; void fun() { int sp,pu,ye; ye=ans; for(;ye>=0;ye--) { for(sp=max(s+p,y)+ye;sp<=12+m;sp++) { for(pu=p+ye;pu<=sp-s;pu++) { if(pu+ye+sp==12+m) { printf("%d %d %d\n",sp,pu,ye); return; } } } } } int main() { while(cin>>s>>p>>y>>m) { ans=(12+m-max(s+p,y)-p)/2;//yertle<=ans fun(); } return 0; }
1421: Repeat Number
时间限制: 1 Sec 内存限制: 32 MB提交: 63 解决: 26
[提交][状态][讨论版]
题目描述
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 RepeatNumbers 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.先打表出所有的repeat number再暴力 出x,y的组合个数
#include<iostream> #include<cstdio> using namespace std; // 2*x<=a+b<=2*y int a[100],t; void inti(){ int i,j; t=0; for(i=11;i<=11111111;i=i*10+1) { for(j=1;j<=9;j++)a[t++]=i*j; } // for(i=0;i<t;i++)printf("%d\n",a[i]); } int main(){ inti(); int x,y,p,q,i; while(cin>>x>>y) { for(i=0;i<t;i++) { if(a[i]>=2*x){ p=i; break; } } if(i==t){ printf("0\n"); continue; } for(i=t-1;i>=0;i--){ if(a[i]<=2*y) { q=i; break; } } if(i==-1) { printf("0\n"); continue; } int sum=0; for(i=p;i<=q;i++) { if(a[i]%2==0)// x=[x,a[i]/2] y=[a[i]/2,y] st:x=6,y=12 sum+=min(a[i]/2-x+1,y-a[i]/2+1); else //x=[x,a[i]/2] y=[a[i]/2+1,y] st: x=3,y=10; sum+=min(a[i]/2-x+1,y-a[i]/2); } printf("%d\n",sum); } return 0; }
相关文章推荐
- 二分优化的暴力枚举
- hdu1015 Safecracker (暴力枚举)
- 蓝桥杯PREV-3 全排列暴力技巧枚举
- SCU 4489 misaka and last order(暴力枚举)
- Sheldon Numbers (暴力枚举)
- 2017蓝桥杯模拟题 猜算式(暴力枚举)
- 【蓝桥杯-暴力枚举简化技巧】平方和
- 2017蓝桥杯模拟题 风险度量(暴力枚举)
- 动态规划之暴力枚举不断尝试
- 算法学习笔记(一)------暴力之枚举
- POJ-3187 Backward Digit Sums (暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 7 街区最短路径问题 暴力枚举
- 10277 Boastin' Red Socks(概率 暴力枚举)
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- zoj 3954 Seven-Segment Display(暴力枚举)
- 蓝桥杯 六角填数(dfs || 暴力枚举)
- bzoj 1800 暴力枚举
- Fliptile POJ - 3279 (状态压缩+枚举) && Flip Game POJ - 1753(状态压缩+bfs暴力)