Smith Numbers POJ - 1142 暴力递归枚举】的更多相关文章

题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果   x的每一数位的和   等于  x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: 4937775 = 3 * 5 * 5 * 65837 电话号码的所有数字的和为4+9+3+7+7+7+5= 42,其质因数的数字的和为3+5+5+6+5+ 5+8+3+7=42. 题解: 暴力,具体见代码 代码: 1 #include<stdio.h> 2 #include<string.…
题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路:主要是分治:分解成质因子使用递归即可. #include<cstdio> #include<cmath> // 检测素数 bool is_prime(int n) { ; i*i <= n;++i) ){ ; } ; } //数位 int sumfun(int n) { ; ;…
While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that number was equal to…
Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University, noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that nu…
                               Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14521   Accepted: 4906 Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed tha…
Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that number w…
题意: 给出4*4的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法:暴力dfs枚举 棋子只有最多翻一次,因为翻两次后结果和不翻是一样的,所以整个棋盘最多翻16次. 用step代表翻转的次数,当翻转了step次时,就看一下整个棋盘是否是清一色的.   当棋盘是清一色的时候就直接输出step,得到的就是最少翻转次数使棋盘清一色. 第二种方法:利用位运算来优化 因为棋子不…
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10042.html 原创:Smith Numbers - PC110706 作者:MilkCu 题目描述 Smith Numbers   While skimming his phone directory in 1982, mathematician Albert Wilansky noticed that the telepho…
POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴力枚举暴力枚举.数据量为8000,O(n^2). */ #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #incl…
Poj1142 Smith Numbers Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13854 Accepted: 4716 Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telepho…
递归枚举文件并操作 #!/bin/bash CURDIR=$(cd $(dirname $0); pwd) export GOPATH=$CURDIR/.. echo GOPATH=$GOPATH cd $GOPATH/src/battle/luajit_c/src luafiles=$(find $CURDIR -name '*.lua') for i in ${luafiles[@]} do echo $i ./luajit -b $i $i done read -p "press any…
题目一(poj-2965):传送门 思路:递归+枚举,遍历每一种情况,然后找出最小步骤的结果,与poj-1753类似. #include<iostream> #include<cstdio> #include<cstring> //#include<ctime> using namespace std; ],y[],xx[],yy[],ans=; ]; ][]; void turn(int len) { ,y=len%; ;i<;i++) { a[x]…
1,关键词解释 1.1 暴力递归: 1, 把问题转化为规模缩小了的同类问题的子问题 2, 有明确的不需要继续进行递归的条件(base case) 3, 有当得到了子问题的结果之后的决策过程 4, 不记录每一个子问题的解 1.2 动态规划: 1, 从暴力递归中来 2, 将每一个子问题的解记录下来,避免重复计算 3, 把暴力递归的过程,抽象成了状态表达 4, 并且存在化简状态表达,使其更加简洁的可能 2,学会尝试才能掌握 2.1 P类问题和NP问题 P类问题:时间复杂度为多项式: 知道怎么算,让计算…
Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University , noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits o…
Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14173   Accepted: 4838 Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telephone number of his b…
算法新手,刷力扣遇到这题,搞了半天终于搞懂了,来这记录一下,欢迎大家交流指点. 题目描述: 给你一个整数数组 nums ,找到其中最长严格递增子序列的长度. 子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序.例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列. 解法一:暴力递归 不解释,先暴力搞一下.(时间复杂度O(n^3),不行) 1 class Solution { 2 public: 3 int l(vector<int>&…
http://poj.org/problem?id=1142 题意: 给出一个数n,求大于n的最小数,它满足各位数相加等于该数分解质因数的各位相加. 思路:直接暴力. #include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <cmath> using namespace std; in…
题意:题目定义了一个史密斯数,这个数的定义是:一个合数的各个位置上加起来的和等于它的素因数所有位置上的数字加起来的和.比如: 4937775=3∗5∗5∗658374+9+3+7+7+7+5=3+5+5+6+5+8+3+7=42 题目让你找出比n大的数中最小的这个数.另外:素数不是史密斯数   题解: 运用好递归,暴力枚举   代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #inc…
完全想不到啊,同余模定理没学过啊,想起上学期期末考试我问好多同学'≡'这个符号什么意思,都说不知道,你们不是上了离散可的吗?不过看了别人的解法我现在会了,同余模定理介绍及运用点这里点击打开链接 简单说一下同余模定理:如果(a - b) / m = 0,说明a%m等于b%m,那么对于本题应该如何运用呢?  已知a % n = m,那么(a * 10 + x) % n = a * 10 % n + x % n = (a % n * 10 + x ) % n = (m *10 + x ) % n,有了…
思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using namespace std; int n,cnt; struct Point{int x,y;}point[888]; struct ans{int x,y,z;}ans[888]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)…
e.... 米还是没有读懂题....T_T ..... e.... 这就是传说中的暴力吗....太血腥了....太暴力了...九重for循环....就这么赤裸裸的AC了.... 水是水了点..但是..我也没想到可以这样解..因为每种操作最多只能进行三次 不然就是重复了..所以...附代码: #include<stdio.h>#include<iostream>#include<string.h>#define FOR(x) for (x=0; x<=3; ++x)…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted: 7689 Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices.…
题目链接:http://poj.org/problem?id=2653 Time Limit: 3000MS Memory Limit: 65536K Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that…
SubsetTime Limit: 30000MS        Memory Limit: 65536KTotal Submissions: 6754        Accepted: 1277 DescriptionGiven a list of N integers with absolute values no larger than 1015, find a non empty subset of these numbers which minimizes the absolute v…
1140 Look-and-say Sequence(20 分) 题意:观察序列D, D1, D111, D113, D11231, D112213111, ...,显然后一个串是对前一个串每一小段连续相同的字母及其个数的描述.例如,D112213111是对D11231的描述,原因是在D11231中,依次出现了1个D(即D1),2个1(即12),1个2(即21),1个3(即31),1个1(即11), 连起来即为D112213111.给定D,问符合该规律的序列中第N个数是多少? 分析: 1.C++…
 强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是不是素数,然后还有一个很重要的问题,那就是a和p是不互质的,不要用a^(p-1)=1(mod p)这个判据,比如4^6=4(mod 6),但是4^5=4(mod 6) #include <iostream> #include <functional> #include <algo…
题目链接:http://poj.org/problem?id=2784 Buy or Build Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1528   Accepted: 592 Description World Wide Networks (WWN) is a leading company that operates large telecommunication networks. WWN would li…
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains…
今天这个问题是我之前一直想解决的,还记得以前第一次上蓝桥杯的课的时候,也就是大一高数期中模拟考试那天,下午去上蓝桥杯课,遇到这道题,当时写了写,根本没有思路,然后就给大一的模拟考试去了.印象深刻啊,一直没写出来.先来说一下题目吧. 1.问题描述: 如下图所示的数字三角形,编写一个程序计算从顶部到底部某一处的一条路径,使得该路径数字和最大,输出路径和最大值. 7 3      8 8      1      0 2      7      4      4 4      5      2     …