problem1 link

如果decisions的大小为0,那么每一轮都是$N$个人。答案为0.

否则,如果答案不为0,那么概率最大的一定是一开始票数最多的人。因为这个人每一轮都在可以留下来的人群中。

假设第一轮之后剩下$r_{1}$个人,那么第二轮之后将剩下$r_{2}=N$%$r_{1}$个人。不妨设$r_{1}<N$。第一轮能够使得$r_{1}$个人的票数答案一样多且最多(设这个票数为$x$),那么这个x一定是大于等于单纯由decisions决定出的最大值。而现在$r_{1}<N$了,所以必然现在能投出的最大值还是大于等于第一轮的最大值。最后结果是:一些人的票数是$N/r_{1}$,另外一些是$N/r_{1}+1$,那么后一部分人将留下来到下一轮。

同理第$k$轮之后剩下$r_{k}=N$%$r_{k-1}$个人,直到剩下一个人。当出现$N$%$r_{i}=0$时,说明出现循环,答案为0。

有解的话,答案为$\frac{r_{2}}{r_{1}}*\frac{r_{3}}{r_{2}}*...*\frac{r_{k}}{r_{k-1}}=\frac{r_{k}}{r_{1}}=\frac{1}{r_{1}}$

problem2 link

首先,最后的图形的结果不会超出(-27,0)到(27,81)这个范围。

由于给出的范围都是整数,那么每次用给出的区间$R$与当前图形能扩展出的最大区间$R_{i}$比较,如果$R$能包含$R_{i}$,那么直接计算即可。否则可将当前线段继续增长,出现三个小区间,继续匹配即可。可以看出,最后最小的区间的大小为$1$x$1$。

对于一个线段$p_{1}p_{2}$,设还能增长$t$次,$L=|p_{1}p_{2}|$,那么最后的长度为$L(1+\frac{2}{3}t)$

problem3link

$p_{5}$和$p_{7}$的个数就是5和7的个数。剩下的数字1,2,3,4,6,8,9出现的次数都不能确定。

可以枚举2,4,8出现的次数,这样根据$p_{2}$可以确定6出现的次数,再枚举9出现的次数,然后根据$p_{3}$以及6和9的个数可以确定3的个数,最后根据$S$可以确定1的个数。假设数字$i$出现的个数为$c_{i}$,令总位数$n=\sum_{i=1}^{9}c_{i}$。那么假设最后的某一位为数字$i$的方案数有$f(i)=\frac{(n-1)!}{c_{1}c_{2}...(c_{i}-1)...c_{8}c_{9}}$。然后数字$i$可以在第$0$位到第$n-1$位的任何一位,那么数字$i$对答案的贡献位$g(i)=f(i)*(1+10^{1}+...+10^{n-1})$

code for problem1

public class MafiaGame {

	public double probabilityToLose(int N, int[] decisions) {
int[] c = new int[N];
for (int x : decisions) {
++ c[x];
}
int mx = 0;
for (int x : c) {
mx = Math.max(mx, x);
}
if (mx == 0) {
return 0;
}
int tot = N - decisions.length;
int r = 0;
for (int i = 0; i < N; ++ i) {
if (c[i] <= mx - 1) {
tot -= mx - 1 - c[i];
}
else {
r += 1;
}
}
if (tot > 0) {
r += tot;
}
double result = 1.0 / r;
while (r != 1) {
if (N % r == 0) {
return 0;
}
r = N % r;
}
return result; } }

  

code for problem2

public class FractalPicture {

	static class Point {
int x, y; Point() {}
Point(int x, int y) {
this.x = x;
this.y = y;
}
} static class Rect {
int x1, x2, y1, y2; Rect() {}
Rect(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
} Rect intersect(Rect a) {
return new Rect(Math.max(x1, a.x1),
Math.max(y1, a.y1),
Math.min(x2, a.x2),
Math.min(y2, a.y2));
} boolean contains(Rect r) {
return x1 <= r.x1 && r.x2 <= x2
&&y1 <= r.y1 && r.y2 <= y2;
}
} static Rect extend(Point p1, Point p2) {
if (p1.x == p2.x) {
int y1 = Math.min(p1.y, p2.y);
int y2 = Math.max(p1.y, p2.y);
int detx = Math.max(1, (y2 - y1) / 3);
return new Rect(p1.x - detx, y1, p1.x + detx, y2);
}
else {
int x1 = Math.min(p1.x, p2.x);
int x2 = Math.max(p1.x, p2.x);
int dety = Math.max(1, (x2 - x1) / 3);
return new Rect(x1, p1.y - dety, x2, p1.y + dety);
}
}
static int length(Point p1, Point p2) {
if (p1.x == p2.x) {
return Math.abs(p1.y - p2.y);
}
return Math.abs(p1.x - p2.x);
} public double getLength(int x1, int y1, int x2, int y2) {
Point p1 = new Point(0, 0);
Point p2 = new Point(0, 81);
Rect r = new Rect(x1, y1, x2, y2).intersect(extend(p1, p2));
return dfs(r, p1, p2, 499);
} static int segIntersectSeg(int L1, int R1, int L2, int R2) {
return Math.max(0, Math.min(R1, R2) - Math.max(L1, L2));
} static int rectIntersectSegment(Rect i, Point p1, Point p2) { assert i.x1 <= i.x2 && i.y1 <= i.y2; if (p1.x == p2.x) {
int x = p1.x;
int y1 = Math.min(p1.y, p2.y);
int y2 = Math.max(p1.y, p2.y);
if (i.x1 <= x && x <= i.x2) {
return segIntersectSeg(i.y1, i.y2, y1, y2);
}
else {
return 0;
}
}
else {
int y = p1.y;
int x1 = Math.min(p1.x, p2.x);
int x2 = Math.max(p1.x, p2.x);
if (i.y1 <= y && y <= i.y2) {
return segIntersectSeg(i.x1, i.x2, x1, x2);
}
else {
return 0;
}
} } static double calculate(Point p1, Point p2, int t) {
return length(p1, p2) * (1.0 + t * 2.0 / 3.0);
} static double calculateUnit(Rect r, Point p1, Point p2, int t) {
double tot = calculate(p1, p2, t);
if (p1.x == p2.x) {
int x = p1.x;
int y1 = Math.min(p1.y, p2.y);
int y2 = Math.max(p1.y, p2.y);
if (r.x1 <= x && x <= r.x2 && r.y1 <= y1 && y2 <= r.y2) {
if (r.x1 == x || r.x2 == x) {
return (tot - 1) * 0.5 + 1;
}
return tot;
}
return 0;
}
else {
int y = p1.y;
int x1 = Math.min(p1.x, p2.x);
int x2 = Math.max(p1.x, p2.x);
if (r.y1 <= y && y <= r.y2 && r.x1 <= x1 && x2 <= r.x2) {
if (r.y1 == y || r.y2 == y) {
return (tot - 1) * 0.5 + 1;
}
return tot;
}
return 0;
}
} static Point[] explode(Point p1, Point p2) { if (p1.x == p2.x) {
int len = p2.y - p1.y;
Point pp1 = new Point(p1.x, p1.y + len / 3 * 2);
Point pp2 = new Point(p1.x - len / 3, pp1.y);
Point pp3 = new Point(p1.x + len / 3, pp1.y);
return new Point[]{pp1, pp2, pp3};
}
else {
int len = p2.x - p1.x;
Point pp1 = new Point(p1.x + len / 3 * 2, p1.y);
Point pp2 = new Point(pp1.x, p1.y - len / 3);
Point pp3 = new Point(pp1.x, p1.y + len / 3);
return new Point[]{pp1, pp2, pp3};
}
} double dfs(Rect r, Point p1, Point p2, int t) {
if (r.x1 > r.x2 || r.y1 > r.y2) {
return 0;
}
if (t == 0) {
return rectIntersectSegment(r, p1, p2);
}
if (r.contains(extend(p1, p2))) {
return calculate(p1, p2, t);
} if (length(p1, p2) == 1) {
return calculateUnit(r, p1, p2, t);
}
Point[] ps = explode(p1, p2);
double result = rectIntersectSegment(r, p1, ps[0]);
result += dfs(r, ps[0], ps[1], t - 1);
result += dfs(r, ps[0], ps[2], t - 1);
result += dfs(r, ps[0], p2, t - 1);
return result; }
}

code for problem3

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class ProductAndSum { final static int mod = 500500573; public int getSum(int p2, int p3, int p5, int p7, int S) {
long[] p = new long[S + 1];
long[] q = new long[S + 1];
p[0] = q[0] = 1;
for (int i = 1; i <= S; ++ i) {
p[i] = p[i - 1] * i % mod;
q[i] = pow(p[i], mod - 2);
} long[] f = new long[S + 1];
f[0] = 1;
for (int i = 1, b = 1; i <= S; ++ i) {
b = (int)(b * 10L % mod);
f[i] = (f[i - 1] + b) % mod;
}
int[] c = new int[10];
c[5] = p5;
c[7] = p7;
long result = 0;
for (c[2] = 0; c[2] <= p2; ++ c[2]) {
for (c[4] = 0; c[4] * 2 + c[2] <= p2; ++ c[4]) {
for (c[8] = 0; c[8] * 3 + c[4] * 2 + c[2] <= p2; ++ c[8]) {
c[6] = p2 - c[2] - c[4] * 2 - c[8] * 3;
for (c[9] = 0; c[9] * 2 +c[6] <= p3; ++ c[9]) {
c[3] = p3 - c[6] - c[9] * 2;
c[1] = S;
for (int i = 2; i <= 9; ++ i) {
c[1] -= c[i] * i;
}
if (c[1] < 0) {
continue;
}
int n = 0;
for (int i = 1; i <= 9; ++ i) {
n += c[i];
}
long k = p[n - 1];
for (int i = 1; i <= 9; ++ i) {
k = k * q[c[i]] % mod;
}
for (int i = 1; i <= 9; ++ i) {
if (c[i] != 0) {
result += k * p[c[i]] % mod * q[c[i] - 1] % mod * f[n - 1] % mod * i % mod;
result %= mod;
}
}
}
}
}
}
return (int)result;
} static long pow(long a, long b) {
a %= mod;
long result = 1;
while (b > 0) {
if (b % 2 == 1) {
result = result * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return result;
}
}

  

topcoder srm 500 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 563 Div1 500 SpellCards

    题意 [题目链接]这怎么发链接啊..... 有\(n\)张符卡排成一个队列,每张符卡有两个属性,等级\(li\)和伤害\(di\). 你可以做任意次操作,每次操作为以下二者之一: 把队首的符卡移动到队 ...

  4. TopCoder SRM 675 Div1 Problem 500 LimitedMemorySeries1(分块)

    题意  给定一个长度不超过$5*10^{6}$的数列和不超过$100$个询问,每次询问这个数列第$k$小的数,返回所有询问的和 内存限制很小,小到不能存下这个数列.(数列以种子的形式给出) 时限$10 ...

  5. topcoder srm 440 div1

    problem1 link 二分答案,然后计算总时间.跟$T$比较确定要增大答案还是减小答案. problem2 link 可以看作是以‘*’所在位置为根的树.所以每个非根节点都有一个父节点. 那么每 ...

  6. topcoder srm 714 div1

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

  7. topcoder srm 706 div1

    1.给定一个迷宫,点号表示不可行,井号表示可行.现在可以改变其中的一些井号的位置.问最少改变多少个井号可以使得从左上角到右下角存在路径. 思路:设高为$n$,宽为$m$,若井号的个数$S$小于$n+m ...

  8. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

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

  9. Topcoder SRM 602 div1题解

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

随机推荐

  1. Hibarnate控制台打印不出sql,并且报出异常:org.hibernate.exception.JDBCConnectionException: Cannot open connection

    1.认真查看hibarnate.cfg.xml文件中连接数据库的各个信息是否正确;如果正确看下一步; 2.MySQL版本>=5.6.X,对应的mysql-connector-java jar 的 ...

  2. python pandas模块,nba数据处理(1)

    pandas提供了使我们能够快速便捷地处理结构化数据的大量数据结构和函数.pandas兼具Numpy高性能的数组计算功能以及电子表格和关系型数据(如SQL)灵活的数据处理能力.它提供了复杂精细的索引功 ...

  3. Codeforces Round #322 (Div. 2) E F

    E. Kojiro and Furrari 题意说的是 在一条直线上 有n个加油站, 每加一单位体积的汽油 可以走1km 然后每个加油站只有一种类型的汽油,汽油的种类有3种 求从起点出发到达终点要求使 ...

  4. java集合类图

  5. Linux服务器---邮件服务spam

    安装spam spam(SpamAssassin)利用perl来进行文字分析,他会检测邮件的标题.内容.送信人,这样就可以过滤出垃圾邮件 1.安装spam.由于spam的依赖太多,用户一定要使用yum ...

  6. Step3 SQL Server 通过备份文件初始化复制

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 搭建过程(Process) 注意事项(Attention) 疑问(Questions) 参考文 ...

  7. 苹果手机显示分享链接的方法html页面

    function onBridgeReady(){ WeixinJSBridge.call('showOptionMenu'); } if (typeof WeixinJSBridge == &quo ...

  8. python里面的xlrd模块

    ♦python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库. 今天就先来说一下xlrd模块: 一.安装xlrd模块 ♦ 到python官网下载 ...

  9. Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFa ...

  10. Linux的简单介绍.

    Linux操作系统概述: Linux是基于Unix的开源免费的操作系统,由于系统的稳定性和安全性几乎成为程序代码运行的最佳系统环境.Linux是由Linux Torvalds(林纳斯·托瓦兹)起初开发 ...