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. npm 安装React Devtools调试工具

    有时候没有***工具时,怎么安装React DevTool, 其一直接搜索到Chrome的插件安装即可. 其二, 可以通过下载github上的react-devtools, 然后打包,最后导入chro ...

  2. Mac虚拟机上使用Genumotion模拟器

    在Mac虚拟机系统上开发ReactNative的IOS应用非常方便,只要安装Xcode即可,  但 Android应用就需要三个步骤: 首先声明,下载Android SDK会非常慢,最好有快速的网络或 ...

  3. js字符串三个编码的区别

    1.escape():编码目的为了防止字符串中特殊字符造成运算错误,主要在字符串运算中使用: 不进行编码的69个字符:A-Z.a-z.0-9.@.*._.+.-...\. 2.encodeURI(): ...

  4. javaweb之验证码验证技术

    今天学习了一个验证码校验技术,所以就写下了一些笔记,方便日后查看.首先创建web工程 1.然后在src目录下创建一个Servlet类,此类用来显示登录页面和错误信息提示 package com.LHB ...

  5. 清华操作系统实验--80x86汇编基础

    前言 80x86架构里,因为历史原因字是16位的,因此在汇编指令中用后缀-b,-w,-l来表示操作数是字节 字 或是双字 C声明 Intel数据类型 汇编代码后缀 大小(字节) char 字节 b 1 ...

  6. callback源码分析——callback_iter和callback

    uvm_callback_iter,定义了function,first,last,next,prev的函数, 其中定义的还是相应uvm_callbacks的静态函数: 所以之前uvm_callback ...

  7. 水题B

    国际象棋的棋盘是黑白相间的8 * 8的方格,棋子放在格子中间.如下图所示: 王.后.车.象的走子规则如下: 王:横.直.斜都可以走,但每步限走一格. 后:横.直.斜都可以走,每步格数不受限制. 车:横 ...

  8. 《大话设计模式》c++实现 模版方法模式

    模板方法模式:定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 角色: (1)AbstractClass:是抽象类,其实也 ...

  9. maven 知识

    1. maven 环境配置 Maven 3.3 要求 JDK 1.7 或以上   Maven 3.2 要求 JDK 1.6 或以上   Maven 3.0/3.1 要求 JDK 1.5 或以上 2. ...

  10. sql 表中删除字段重复的行

    Id    Email    UserName1    Taiseer.Joudeh@hotmail.com    TaiseerJoudeh2    Hasan.Ahmad@mymail.com   ...