power oj 1697

1697: Half -- Power OJ这道题,我网页翻译发现“这不是sb翻译吗”,看了很久的题意,最后理解之后发现这不就是给大家的签到题吗

其实题意就是t组测试,每次给你一个n,然后求10^(n-1)到10^n之中有多少个n,使得能找到一个数d,满足n/d=0.5,n和d的各位数都只出现一次,且不出现0.

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <vector>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <bitset>
typedef long long ll;
const int maxn=2e5+500;
const int mod=1e9+7;
const int N=2005;
const int INF=0x3f3f3f;
using namespace std;

bool check(int x)
{
    int temp1=x,temp2=2*x;
    int a[10]={0}; //该数组为一个标记数组
    while(temp1)   //将该数各个位的数标记
    {
        a[temp1%10]++; 
        temp1/=10;
    }
    while(temp2)
    {
        a[temp2%10]++;
        temp2/=10;
    }
    for(int i=0;i<=9;i++)
    {
        if(a[i]>=2)
        {
            return 0;
        }
    }
    if(a[0])  //判断各个位上是否出现了0
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=(int)pow(10,n-1);i<=(int)pow(10,n);i++)
        {
            if(check(i))
            {
                printf("the form %d/%d = 0.5.\n",i,i*2);
            }
        }
    }
    return 0;
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值