CSU 1425 Prime Summation】的更多相关文章

原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1425 DP题. f[i][j]表示当前数字为i,分解式中最大质数为j的方案数,那么,状态转移方程为: f[i][j] = sum(f[i-j][k]) 其中,k为小于等于j的所有质数. 求具体分解式时可以先转化为从小到大(如样例的“顺数第2”可以表述为“倒数第3”),更容易递推编程. #include <stdio.h> #include <string.h> #defi…
这个题本来有希望在比赛里面出了的 当时也想着用递推 因为后面的数明显是由前面的推过来的 但是在计算的时候 因为判重的问题 ...很无语.我打算用一个tot[i]来存i的总种树,tot[i]+=tot[j]//j为可以由j推到i的一系列数,但这样是不对的,会产生大量重复计算... 看了下标程才发现要用二维来计算出种类总数,f[i][j]+=sum(f[i-j][k]) 表示在推i数的时候,第一个素数为j的种类数,注意j一定为素数,而且k不能大于j...标程里面处理的比较简练,就学了下他的写法. 至…
1756: Prime Submit Page   Summary   Time Limit: 3 Sec     Memory Limit: 128 Mb     Submitted: 281     Solved: 69 Description 如果a,b的最大公约数是1,说明a,b是一对互素的数,给定你n个数字,希望你找出互素的数的对数 Input 第一行输入一个正整数T,表示数据组数 每组数据第一行输入一个正整数n,表示数字的个数(n<=10000) 接下来一行输入n个正整数,每个数字大…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1756 直接暴力O(n^2logn)过不了 两两算gcd 考虑每个数的范围[1,1000]统计一下即可O(1000^2*log(1000)) Notice:1与任何数互质,需要特判(自己与自己互质) Code1 统计 // <1756.cpp> - Wed Oct 19 08:25:53 2016 // This file is made by YJinpeng,created by XuYik…
Description xrdog has a number set. There are 95 numbers in this set. They all have something in common and are all positive integers less than 500. The naughty xiao zhuan has deleted one of the numbers in the set. Can you find the number that xiao z…
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10168.html 原创:Summation of Four Primes - PC110705 作者:MilkCu 题目描述 Summation of Four Primes   Waring's prime number conjecture states that every odd integer is either pri…
Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler proved in one of his classic theorems that prime numbers are infinite in number. But can every number be expressed as a summation of four positive prim…
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1552 Description On an alien planet, every extraterrestrial is born with a number. If the sum of two numbers is a prime number, then two extraterrestrials can be friends. But every extraterrestr…
Description: Count the number of prime numbers less than a non-negative number, n click to show more hints. Credits:Special thanks to @mithmatt for adding this problem and creating all test cases. 求n以内的所有素数,以前看过的一道题目,通过将所有非素数标记出来,再找出素数,代码如下: public i…
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t of test cases in a single line (t<=10). In each of the next t li…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1, 2, . . . , n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle sho…
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h> using namespace std; bool isPrime(int n){//素数判断 || n == ) return true; else{ ; ; i < k; i++){ ) return false; } return true; } } ]; ]; void getPrime…
hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem/3223/ 思路:主要是用了一个Meisell-Lehmer算法模板,复杂度O(n^(2/3)).讲道理,我不是很懂(瞎说什么大实话....),下面输出请自己改 #include<bits/stdc++.h> using namespace std; typedef long long LL;…
题意:在n个星球,每2个星球之间的联通需要依靠一个网络适配器,每个星球喜欢的网络适配器的价钱不同,先给你一个n,然后n个数,代表第i个星球喜爱的网络适配器的价钱,然后给出一个矩阵M[i][j]代表第i个星球到第j个星球联通所需的价钱,求联通所有星球所需的最小价钱 思路:prime 每次加入一条边的时候把边2个点的权值加进去即可 (zoj崩了,题也没法交啊,不知对错,啊~~~) 代码: #include "iostream" #include "string.h" #…
题意:给你一个矩阵M[i][j]表示i到j的距离 求最小生成树 思路:裸最小生成树 prime就可以了 最小生成树专题 AC代码: #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set&…
存图方式 最小生成树prime+队列优化 优化后时间复杂度是O(m*lgm) m为边数 优化后简直神速,应该说对于绝大多数的题目来说都够用了 具体有多快呢 请参照这篇博客:堆排序 Heapsort ///prime队列优化 #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #…
poj1287 裸最小生成树 代码 #include "map" #include "queue" #include "math.h" #include "stdio.h" #include "string.h" #include "iostream" #include "algorithm" #define abs(x) x > 0 ? x : -x #def…
hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Weiming Lake, also named "Un-named Lake", is the most famous scenic spot in Peking University. It is located in the north of the campus and is su…
给定两个四位素数a  b,要求把a变换到b 变换的过程要保证  每次变换出来的数都是一个 四位素数,而且当前这步的变换所得的素数  与  前一步得到的素数  只能有一个位不同,而且每步得到的素数都不能重复. 求从a到b最少需要的变换次数.无法变换则输出Impossible   输入: 第一行 是一个数T 表示下面有T个测试数据 下面T行  每行两个数a b 解题思路:每次变换一次,个十百千,四个位置上的数每个从0-9循环一边一共需要4 * 10 = 40次循环  剪枝之后就没多少了 所以直接暴力…
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1…
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1…
/*本篇为转载,在此申明,具体就是先设定从2以后所有的数都为质数,定为质数的数的倍数则不是质数,慢慢排除后面的数*/ #include<iostream>#include<cstring>using namespace std;const int N = 1300000;//第10万个数为1299709int prime[N];bool notPrime[N]; int main(){  memset(prime,0,sizeof(prime)); memset(notPrime,…
1.Kruskal算法 图的存贮采用边集数组或邻接矩阵,权值相等的边在数组中排列次序可任意,边较多的不很实用,浪费时间,适合稀疏图.      方法:将图中边按其权值由小到大的次序顺序选取,若选边后不形成回路,则保留作为一条边,若形成回路则除去.依次选够(n-1)条边,即得最小生成树.(n为顶点数). Kruskal算法在图G=(V,E)上的运行时间取决于分离集合这一数据结构如何实现.采用在分离集合中描述的按行结合和通路压缩的启发式方法来实现分离集合森林的结构,这是从渐近意义上说,目前最快实现法…
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************************************************************** Problem: User: youmi Language: C++ Result: Accepted Time: Memory: ***********************************…
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive intege…
题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,1,2,... denote the increasing…
题目链接 题意:输入一个数n (2 <= n <= 10000) 有多少种方案可以把n写成若干个连续素数之和 打出10000之内的素数表,然后再打出每个可能得到的和的方案数的表 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; ; ],total,flag[Max + ]; ]; //可以求出1000…
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这样的话点到圆弧的最短距离就是点到圆心的距离减去半径然后再取绝对值就可以了,第二种情况是那个点跟圆心的连线不在那段扇形的圆弧范围内,这样的话,最短的距离就是到这段圆弧的端点的最小值. 接下来的第一步就是求圆心的坐标跟圆的半径,只要求出圆心坐标半径就好说了,求圆心坐标我用的方法是: 设圆心坐标是(a,b…
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a[j]) m = max(m,dp[j]); else if(b[i] == a[j]) dp[j] = m + 1; #include<cstdio> #include<cstring> #include<iostream> #include<algorithm&g…