uva 725 Division
来源:互联网 发布:mac桌面上的文件不见了 编辑:程序博客网 时间:2024/05/22 06:43
此题很简单,就是暴力枚举,当然也需要有策略,只需要遍历所有的分子就可以了,用set存起来,就行了
//// main.cpp// uva 725 - Division//// Created by XD on 15/7/26.// Copyright (c) 2015年 XD. All rights reserved.//#include <iostream>#include <string>#include <queue>#include <stack>#include <stdio.h>#include <stdlib.h>#include <math.h>#include<vector>#include <string.h>#include <string>#include <algorithm>#include <set>#include <map>#include <cstdio>using namespace std ;set<int > g[80] ;bool iscorrect(int t[],int j){ int flag[10] ; memset(flag, 0, sizeof(flag)) ; for (int i = 0; i < 5; i++) { flag[t[i]]= 1 ; } while (j !=0 ) { int temp = j %10 ; j =j /10 ; if (flag[temp] == 1) { return false ; } else{ flag[temp] = 1 ; } } for (int i = 0; i < 10; i++) { if (flag[i]==0) { return false ; } } return true ;}int getT(int t[]){ int weight= 1 ; int result = 0 ; for (int i = 0; i < 5; i++) { result = result + t[i] * weight ; weight*=10 ; } return result ;}int main() { for (int n = 2; n < 80; n++) { g[n].clear() ; int t[5]; for (int i = 0 ; i < 10; i++) {t[0]=i ; for (int j = i+1 ; j < 10; j++) { t[1]= j ; for (int k = j + 1; k < 10; k++) {t[2]= k ; for (int l = k + 1; l < 10; l++) {t[3] = l ; for (int m = l + 1; m < 10; m++) { t[4]=m ; do{ int T = getT(t) ; if (iscorrect(t ,T * n )) { g[n].insert(T) ; } }while (next_permutation(t, t+5)) ; } } } } } } int n ; int pre = 0 ; while (scanf("%d" ,&n)==1 && n!=0) { if (pre!= 0) { printf("\n") ; } pre = n ; if (g[n].size()== 0) { printf("There are no solutions for %d.\n",n) ; } for (set<int >::iterator it = g[n].begin(); it!=g[n].end(); it++ ) { printf("%d / %05d = %d\n" ,*it * n , *it , n ) ; } } return 0;}
0 0
- UVA 725 - Division
- UVA 725 - Division
- UVa 725 - Division
- UVA - 725 Division
- UVa 725 - Division
- UVa 725 Division
- UVa 725 - Division
- Uva 725 Division
- UVA-725除法-Division
- UVA - 725 Division
- uva 725 - Division
- Uva - 725 - Division
- UVA - 725 Division
- uva 725 Division
- 除法(Division, UVa 725)
- UVA 725 Division
- UVA 725 - Division
- UVa 725----Division(枚举)
- 恐高的鸟
- wpf 如何在后台设置附加属性的值
- PAT (Advanced Level) 1046. Shortest Distance (20) 求环中两点之间的距离
- 901-1注册表相应操作
- 3.2.1 正则表达式的语法(2)
- uva 725 Division
- Leetcode: Reverse Linked List
- python 爬虫1 开始,先拿新浪微博开始
- 统计学习方法概论
- 通过buildnumber-maven-plugin把svn版本号打入jar或war包中
- JSP之Model1
- TreeSet、TreeMap、HashSet、HashMap底层实现
- ci高级用法篇之扩展核心类
- 冲绳中文离线地图App上线