problem1 link

两个数字后面都有阶乘符号,可以抵消。

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class ExtraordinarilyLarge { public String compare(String x, String y) { boolean both=false; while(x.endsWith("!")&&y.endsWith("!")) {
x=x.substring(0,x.length()-1);
y=y.substring(0,y.length()-1);
both=true;
}
boolean bswap=false; if(x.endsWith("!")) {
String t=new String(x);
x=y;
y=t;
bswap=true;
}
long xx=Long.valueOf(x);
if(xx==0&&both) {
xx=1;
} long yy=1;
if(y.endsWith("!")) {
int id=y.indexOf("!");
yy=Long.valueOf(y.substring(0,id));
final int num=y.length()-id;
for(int i=0;i<num&&yy<=xx;++i) {
yy=cal(yy,xx);
}
}
else {
yy=Long.valueOf(y);
if(yy==0&&both) {
yy=1;
}
}
if(xx<yy) {
if(bswap) {
return "x>y";
}
return "x<y";
}
else if(xx==yy) {
return "x=y";
}
else {
if(bswap) {
return "x<y";
}
return "x>y";
}
} long cal(long x,long y) {
if(x==0) {
return 1;
}
long result=1;
for(int i=2;i<=x;++i) {
if(result<=y/i) {
result=result*i;
}
else {
return y+1;
}
}
return result;
}
}

problem2 link

在一个有向无环图上进行dp即可。

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class ContestSchedule { public double expectedWinnings(String[] contests) {
final int n=contests.length;
int[][] p=new int[n][3];
for(int i=0;i<n;++i) {
String[] t=contests[i].split("\\W+");
assert t.length==3;
for(int j=0;j<3;++j) {
p[i][j]=Integer.valueOf(t[j]);
}
}
boolean[][] g=new boolean[n][n];
for(int i=0;i<n;++i) {
for(int j=0;j<n;++j) {
if(i==j) {
g[i][j]=false;
continue;
}
if(p[i][1]<=p[j][0]) {
g[i][j]=true;
}
else {
g[i][j]=false;
}
}
}
Queue<Integer> queue=new LinkedList<>();
double[] f=new double[n];
boolean[] inq=new boolean[n];
for(int i=0;i<n;++i) {
inq[i]=true;
f[i]=p[i][2]/100.0;
queue.offer(i);
}
while(!queue.isEmpty()) {
final int u=queue.poll();
inq[u]=false;
for(int i=0;i<n;++i) {
if(g[u][i]) {
final double c=p[i][2]/100.0;
if(f[u]+c>f[i]) {
f[i]=f[u]+c;
if(!inq[i]) {
inq[i]=true;
queue.offer(i);
}
}
}
}
}
double result=0;
for(int i=0;i<n;++i) {
result=Math.max(result,f[i]);
}
return result;
}
}

problem3 link

$n,m$中小的那个必定小于9.这样一行一行进行dp即可。

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class SeatingPlan { public String expectedTrial(int m, int n, int k) {
if(n<m) {
int x=m;
m=n;
n=x;
}
long[][][] f=new long[n+1][1<<m][k+1];
int[] num=new int[1<<m];
num[0]=0;
for(int i=1;i<(1<<m);++i) {
num[i]=num[i>>1]+(i&1);
}
List<List> g=new ArrayList<>();
for(int i=0;i<(1<<m);++i) {
List<Integer> list=new ArrayList<>();
if(((i>>1)&i)!=0) {
g.add(list);
continue;
}
for(int j=0;j<(1<<m);++j) {
if((i&j)==0&&((j>>1)&j)==0) {
list.add(j);
}
}
g.add(list);
}
f[0][0][0]=1;
for(int i=1;i<=n;++i) {
for(int j=0;j<(1<<m);++j) {
for(int t=0;t<=k;++t) {
if(0==f[i-1][j][t]) {
continue;
}
List list=g.get(j);
for(int p=0;p<list.size();++p) {
int s=(int)list.get(p);
if(t+num[s]>k) {
continue;
}
f[i][s][t+num[s]]+=f[i-1][j][t];
}
}
}
}
long result=0;
for(int i=0;i<(1<<m);++i) {
result+=f[n][i][k];
}
if(result==0) {
return "Impossible!";
}
BigInteger sum=BigInteger.ONE;
for(int i=1;i<=k;++i) {
sum=sum.multiply(int2biginteger(n*m-i+1)).divide(int2biginteger(i));
}
long s=Long.valueOf(sum.toString());
long p=gcd(result,s);
result/=p;
s/=p;
return Long.toString(s)+"/"+Long.toString(result);
} static long gcd(long x,long y) {
return y==0?x:gcd(y,x%y);
} static BigInteger int2biginteger(int x) {
return new BigInteger(Integer.toString(x));
}
}

  

topcoder srm 320 div1的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  7. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  8. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

  9. 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)其 ...

随机推荐

  1. HTTP参数污染【转】

    HTTP参数污染注入源于网站对于提交的相同的参数的不同处理方式导致. 例如: www.XX.com/a?key=ab&key=3 如果服务端返回输入key的值,可能会有 一: ab 二:3 三 ...

  2. CSU 1862 The Same Game(模拟)

    The Same Game [题目链接]The Same Game [题目类型]模拟 &题解: 写这种模拟题要看心态啊,还要有足够的时间,必须仔细读题,一定要写一步,就调试一步. 这题我没想到 ...

  3. 关于Sublime Text3的emmet插件和tab快捷键冲突问题

    当使用Sublime text3时会遇到快捷键冲突的问题,其中就有安装Emmet之后,tab无法缩进了, 网上有些说看看Browse Packages目录下是否有PyV8插件安装,该插件一般情况下随E ...

  4. SnmpTools配置

    上网搜索了很多文档,但是snmptools一直没有配置好,原因就是64机器,网上的说法大多直接复制过来的,或者就没有考虑64位机器.经过仔细搜索和测试,一下是详细的配置过程: Index 安装 如果是 ...

  5. Must Know Tips/Tricks in Deep Neural Networks (by Xiu-Shen Wei)

    http://lamda.nju.edu.cn/weixs/project/CNNTricks/CNNTricks.html Deep Neural Networks, especially Conv ...

  6. 20155228 2016-2017-2 《Java程序设计》第9周学习总结

    20155228 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 整合数据库 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则 ...

  7. neuFlow&CNP-卷积计算加速器&神经网络加速芯片生态系统

    上周看到韩松毕业论文,扯出神经网络加速器EIE,刚好这周调研了一下neuFlow,扯出09年的一篇做卷积加速的文章,大牛Lecun Yan的学生做的,一晃眼,快十年了.也记录之. 这一套还没研究透,又 ...

  8. Hive中如何快速的复制一张分区表(包括数据)

    Hive中有时候会遇到复制表的需求,复制表指的是复制表结构和数据. 如果是针对非分区表,那很简单,可以使用CREATE TABLE new_table AS SELECT * FROM old_tab ...

  9. linux常用命令:ls命令

    ls命令是linux下最常用的命令.ls命令就是list的缩写,缺省下ls用来打印出当前目录的清单,如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linux ...

  10. 微信小程序制作家庭记账本之二

    第二天,继续学习制作记账本,网上搜寻别人的源码进行学习,但是搜寻过程中总是能看到github这个东西,不清楚这是什么东西,明天继续努力吧.