topcoder srm 370 div1
problem1 link
枚举每一种大于等于$n$的计算其概率即可。
problem2 link
首先二分答案,然后计算。令$f[i][j]$表示移动完前$i$最后一个在位置$j$的最小代价。
problem3 link
假如一个数质因子分解为$n=p_{1}^{x_{1}}p_{2}^{x_{2}}..p_{t}^{x_{t}}$,那么其约数的个数为$(x_{1}+1)(x_{2}+1)..(x_{t}+1)$
所以只需要将$k$分解成若干数字之积,然后分配每个约数最小的一些质数即可。
令$f[i][j]$表示到第$i$个质数,还剩下的数字之积为$j$的最小值。
code for problem1
import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class DrawingMarbles { public double sameColor(int[] colors,int n) {
int m=0;
for(int i=0;i<colors.length;++i) {
m+=colors[i];
}
double result=0;
for(int i=0;i<colors.length;++i) {
if(colors[i]<n) {
continue;
}
double t=1;
for(int k=0;k<n;++k) {
t*=1.0*(colors[i]-k)/(m-k);
}
result+=t;
}
return result;
}
}
code for problem2
import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class ConnectTheCities { public int minimalRange(int distance, int funds, int[] position) {
Arrays.sort(position);
int low=1,high=distance;
int result=high;
while(low<=high) {
int mid=(low+high)>>1;
if(check(mid,distance,funds,position)) {
result=Math.min(result,mid);
high=mid-1;
}
else {
low=mid+1;
}
}
return result;
}
boolean check(int mid,int distance,int funds,int[] positions) {
final int n=positions.length;
int[][] f=new int[n+1][distance+1];
for(int i=0;i<n+1;++i) {
for(int j=0;j<distance+1;++j) {
f[i][j]=-1;
}
}
f[0][0]=0;
for(int i=1;i<=n;++i) {
for(int j=0;j<distance+1;++j) {
if(-1==f[i-1][j]) {
continue;
}
for(int k=j;k<=j+mid&&k<=distance;++k) {
final int cost=f[i-1][j]+Math.abs(positions[i-1]-k);
if(cost>funds) {
continue;
}
if(f[i][k]==-1||f[i][k]>cost) {
f[i][k]=cost;
}
}
}
}
for(int i=distance-mid;i<=distance;++i) {
if(i>=0&&f[n][i]!=-1) {
return true;
}
}
return false;
}
}
code for problem3
import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class NumberOfDivisors { final static int N=100;
final static int MAX=50000;
final static long INF=1000000000000000000L; long[][] f=new long[N][MAX+1];
int[] p=new int[N]; public long smallestNumber(int n) {
if(n==1) {
return 1;
}
for(int i=0,k=2;i<N;++i) {
while(!isPrime(k)) {
++k;
}
p[i]=k++;
}
for(int i=0;i<N;++i) {
for(int j=0;j<n+1;++j) {
f[i][j]=-1;
}
}
return dfs(0,n)<=INF?dfs(0,n):-1;
} long dfs(int id,int n) {
if(n==1) {
return 1;
}
if(f[id][n]!=-1) {
return f[id][n];
}
f[id][n]=pow(p[id],n-1);
for(int i=2;i*i<=n;++i) {
if(n%i!=0) {
continue;
}
for(int j=0;j<2;++j) {
final int cur=j==0?i:n/i;
final int nxt=n/cur;
long t=pow(p[id],cur-1);
if(t>INF/dfs(id+1,nxt)) {
t=INF+1;
}
else {
t*=dfs(id+1,nxt);
}
if(f[id][n]>t&&t!=INF+1) {
f[id][n]=t;
}
}
}
return f[id][n];
} long pow(long n,long m) {
long result=1;
while(m>0) {
if(1==(m&1)) {
if(result>INF/n) {
return INF+1;
}
result*=n;
if(m==1) {
break;
}
}
if(n>INF/n) {
return INF+1;
}
n=n*n;
m>>=1;
}
return result;
} boolean isPrime(int x) {
for(int i=2;i*i<=x;++i) {
if(x%i==0) {
return false;
}
}
return true;
}
}
topcoder srm 370 div1的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
- topcoder srm 575 div1
problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...
随机推荐
- sqli-labs(十二)(union以及select的过滤)
第二十七关: 这关禁用了空格和select,空格还是可以使用()代替,select发现可以大小写绕过 输入?id=1'||extractvalue(1,concat(0x5c,(selEct(grou ...
- 【Spring学习笔记-MVC】Spring MVC之多文件上传 (zhan)
http://www.cnblogs.com/ssslinppp/p/4607330.html (zhan)
- linux的swap相关
linux的系统采用的内存方案一般都是 物理内存+swap.物理内存供日常使用,swap用来救急. 但在实际使用的过程中,发现有时候物理内存还没被完全占用的情况下,已经开始使用swap了.而这时候,由 ...
- 软工网络15团队作业4——Alpha阶段敏捷冲刺3.0
软工网络15团队作业4--Alpha阶段敏捷冲刺3.0 1.每天举行站立式会议,提供当天站立式会议照片一张. 2.项目每个成员的昨天进展.存在问题.今天安排. 成员 昨天已完成 今天计划完成 郭炜埕 ...
- uvm设计分析——field automation
uvm中的field_automation主要实现了class中的基础元素的copy,compare等函数, 实现方式分为两种:1)用户注册,field系列宏:uvm内部调用static status ...
- Rpgmakermv(15) PH任务插件
插件介绍 一个用来简单显示任务阶段的任务书 使用方法 插件安装 下载js文件放置到游戏目录/plugins目录下.打开插件管理器,选择PH_QuestBook.js并开启. 插件参数 Show in ...
- request.getServletPath(),request.getContextPath()
2018-11-24 16:34:33 1. getServletPath():获取能够与“url-pattern”中匹配的路径,注意是完全匹配的部分,*的部分不包括. 2. getPageInfo ...
- JavaScript 基础,登录验证
1.<script></script>的三种用法: a.放在<body>中 b.放在<head>中 c.放在外部JS文件中 <!DOCTYPE h ...
- 【Hive学习之八】Hive 调优【重要】
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...
- wifi pj WiFiPhisher 安装使用
1.安装kali linux: https://blog.csdn.net/qq_42545206/article/details/82788119 https://www.kali.org/down ...