UVA - 10396 Vampire Numbers 暴力+打表

题目大意:给出n,要求你输出所有符合规则的n位数

规则如下,这个n位数由两个n/2位数相乘得到,并且满足

1.这n位数为偶数

2.这两个n/2位数上的所有数刚好组成了这n位数

3.两个n/2位数不能都是10的倍数

解题思路:因为输入只有4,6,8,所以先预处理,暴力枚举4,6,8的情况,然后打表

#include<cstdio>
#include<set>
#include<cmath>
using namespace std;
#define maxn 10
set<int> ans[maxn];
int vis[maxn];

void init(int n) {
    int start = pow(10,n-1);
    int end = pow(10,n);
    int MIN = pow(10,2 * n -1);
    int MAX = pow(10,2*n);
    for(int i = start; i < end; i++)
        for(int j = i; j < end; j++) {
            if(i % 10 == 0 && j % 10 == 0)
                continue;
            int t = i * j;
            if(t % 2 || t < MIN || t >= MAX)
                continue;
            int x = i, y = j;
            for(int i = 0; i < 10; i++)
                vis[i] = 0;
            while(x) {
                vis[x % 10]++;
                x = x / 10;
            }
            while(y) {
                vis[y % 10]++;
                y = y / 10;
            }
            bool flag = true;
            int tt;
            while(t) {
                tt = t % 10;
                if(vis[tt] == 0) {
                    flag = false;
                    break;
                }
                vis[tt]--;
                t /= 10;
            }
            if(flag)
                ans[n*2].insert(i*j);
        }
}

int main() {
    int n;
    init(2);
    init(3);
    init(4);
    while(scanf("%d", &n) == 1)  {
        for(set<int>::iterator it = ans[n].begin(); it != ans[n].end(); it++)
            printf("%d\n", *it);
        printf("\n");
    }
    return 0;
}
时间: 2024-10-31 15:42:26

UVA - 10396 Vampire Numbers 暴力+打表的相关文章

筛法暴力打表 --- hdu : 12876 Quite Good Numbers

Quite Good Numbers Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 77, Accepted users: 57 Problem 12876 : No special judgement Problem description A "perfect" number is an integer that is equal to the sum

HDU 4325 Vampire Numbers 打表

杭电服务器是慢啊.. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set> #include <vector> #include <map> using namespace std; #define ll long long #define N

UVA - 12046 Great Numbers

Description Problem G - Great Numbers In this problem you have to count the number of great numbers of length n. Here a great number must have the following property: the number must be divisible by all of its decimal digits. it does not contain any

uva 12009 - Avaricious Maryanna(暴力)

题目连接:uva 12009 - Avaricious Maryanna 题目大意:给定n,求x,x为n位数,并且x*x的后n位还是x. 解题思路:打个表会发现其实有规律,除了n=1的时候多了0和1,其他都是n-1位的基础上再新增一位数,1位的时候是5,6. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 500; int a[

XTU OJ 1210 Happy Number (暴力+打表)

Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number contain all digit 7 or only 1 digit other than 7. For example, 777 is a happy number because 777 contail all digit 7, 7177 and 87777 both happy number

HDU 1058 Humble Numbers (dp+打表)

先是想筛法素数表啊,然后1~2000000000枚举打表啊,结果越想越不对. 后来想到唯一分解定理,可是怎么实现呢..果然还是需要努力啊.. 研究了discuss代码,码之~ ~~~~ dp的思想,若dp[i]是Humble Numbers,那么dp[i]*2,dp[i]*3,dp[i]*5,dp[i]*7都将是Humble Numbers. 所以只需要注意连续性便好了. #include<cstdio> #include<algorithm> #include<cmath&

HDU 1012 u Calculate e【暴力打表,水】

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46844    Accepted Submission(s): 21489 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

uva 467 - Synching Signals(暴力+数学)

题目连接:uva 467 - Synching Signals 题目大意:有n个红绿灯,给出红灯的时间t,那么该灯从0时刻开始就以2*t为周期绿黄红三灯交替,时间分别为t-5,5,t.问所这n个等从第一变为有一个灯不为绿灯开始,要多久才能变成所有的灯刚好都为绿灯.时间超过1小时输出unable to synch after one hour. 解题思路:一小时才3600秒,枚举秒数判断即可. #include <cstdio> #include <cstring> #include

uva 618 - Doing Windows(暴力+数学)

题目链接:uva 618 - Doing Windows 题目大意:给出电脑桌面的大小W和H,现在在桌面上有4个窗口,给出窗口的初始大小,问说能不能通过调整各个窗口的大小(长宽比例不能变)使得4个屏幕刚好占满整个屏幕,并且互相不覆盖. 解题思路:其实可以直接暴力出所有情况,不过细节比较多,而且要考虑所有的细节. 我的做法的是先将4个窗口缩小至最小的状态,然后枚举左下角的窗口, 有四种可能 蓝色部分为另外枚举的窗口,3,4种情况要分别保证说长.宽相等,然后S部分就是子问题. 所以用一个二进制数来表