暴力枚举

ZOJ1095

这题只要枚举出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[n]);
    }
    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 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.

样例输入

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;
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值