import java.util.Scanner;public class Sum { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.ou...
分类:
其他好文 时间:
2014-08-11 17:13:42
阅读次数:
218
//计算抽奖的概率
function get_rand($proArr) {
$result = '';
$proSum = array_sum($proArr);
foreach ($proArr as $key => $proCur) {
$randNum = mt_rand(1, $proSum);
if ($randNum <= $proCur) {
...
分类:
Web程序 时间:
2014-08-11 15:09:32
阅读次数:
236
//计算1-100之间的和//intsum=100;//存储和//for(inti=1;i<100;i++){//sum+=i;//}//printf("1--100的和是:%d",sum);//计算1--100之间偶数的和intsum=0;for(inti=1;i<100;i++){if(i%2!=0){continue;}sum+=i;}printf("%d",sum)第二种方法intsum=0;for(inti=1;i<100;i++)..
分类:
其他好文 时间:
2014-08-11 10:18:32
阅读次数:
234
//定义一个有20个元素的数组,每一个元素的取值范围是[30,70],求他们的和
inta[20]={0};
intsum=0;
for(inti=0;i<20;i++){
a[i]=arc4random()%(70-30+1)+30;
printf("%d",a[i]);
sum+=a[i];
}
printf("\n%d",sum);
return0;
}
分类:
其他好文 时间:
2014-08-11 03:01:01
阅读次数:
189
解题报告
题意:
求逆序数。
思路:
线段树离散化处理。
#include
#include
#include
#include
#define LL long long
using namespace std;
LL sum[2001000],num[501000],_hash[501000];
void push_up(int rt)
{
sum[rt]=sum[rt...
分类:
其他好文 时间:
2014-08-11 00:22:01
阅读次数:
255
题目:求一个数字n拆成k个数字的拆法数,可以重复,可以有0。
分析:dp,组合数学。
方法1:dp
状态:f(i,j)为 j 拆成 i 个数字的方法数,则有f(i,j)= sum(f(i,k)) { 0 ≤ k ≤ j };
方法2:计数原理
隔板法:C(n+k-1,k-1)= (n+1)(...
分类:
其他好文 时间:
2014-08-10 21:39:40
阅读次数:
284
//1481#include #include using namespace std;#define N 50010int parent[N],sum;void init(){ for(int i=1;in || y> n) {sum--;continue;} ...
分类:
其他好文 时间:
2014-08-10 21:29:30
阅读次数:
294
Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[?...
分类:
其他好文 时间:
2014-08-10 21:18:20
阅读次数:
232
Consider integer numbers from 1 to n. Let us call the sum of digits of an integer number its weight. Denote the weight of the number x as w(x).
Now let us order the numbers using so called graduated ...
分类:
其他好文 时间:
2014-08-10 18:47:20
阅读次数:
406
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2121
题意:n个顶点,m条边,求从某一点起建立有向图最小生成树并且花费最小,输出最小花费和根节点下标。
思路:这道题根是不确定的,我们可以先假设一个根,从这个根出发到任何一点的距离(sum)都比原图总权值还大,这样保证了虚拟的边不会是最小入边,也为之后判断是否生成了最小树形图提供方便,从这个点...
分类:
其他好文 时间:
2014-08-10 18:45:40
阅读次数:
271