problem1 link

用$f[i][0],f[i][1]$表示从$i$位置开始Alice是先手是否可以胜利,是后手是否可以胜利。

problem2link

每次钱数够$price$时可以选择使得$n$或者$k$中较小的一个增加1。最多也就增加$2*10^{6}$次。钱数不够$price$时可以直接算出还要多少次可以够$price$。每一次也可以直接计算出不再变化$n,k$而直接挣够$target$时的次数。

problem3 link

如果$k$足够大,最后一定是在某一个区间$[L,R]$循环。当从左到右到达$R$之后,其要选择的循环的$L$一定是满足使得$sum(i,R)$最大的$i$。

那么现在就是应该尽快第一次到达$R$。

设$minTime[i],maxScore[i]$表示从0到达$i$并且下一次应该朝左时最小次数,以及在次数最小情况下最大的分数。

那么每次到达$i$时,一定是在$i$进行了若干次循环$[x,i]$后,从$i$到达了后面的某个$j$。在$i$循环的次数就是满足到达$j$不为负值的最小值。

code for problem1

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class OrderedNim { public String winner(int[] layout) {
final int n = layout.length;
boolean s0 = true;
boolean s1 = false;
for (int i = n - 2; i >= 0; --i) {
boolean t0, t1;
if (layout[i] == 1) {
t0 = s1;
t1 = s0;
}
else {
if (s0 || s1) {
t0 = true;
t1 = false;
}
else {
t0 = false;
t1 = true;
}
}
s0 = t0;
s1 = t1;
}
if (s0) {
return "Alice";
}
return "Bob";
}
}

  

code for problem2

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class StrongEconomy { public long earn(long n, long k, long price, long target) {
if (n >= (target + k - 1) / k) {
return 1;
}
long result = Long.MAX_VALUE;
long usedDays = 0;
long sum = 0;
while (n * k < target) {
long speed = n * k;
result = Math.min(result, usedDays + (target - sum + speed - 1) / speed);
if (sum < price) {
long d = (price - sum + speed - 1) / speed;
sum += speed * d;
usedDays += d;
}
sum -= price;
if (n < k) {
++n;
}
else {
++k;
}
}
result = Math.min(result, usedDays + 1);
return result;
}
}

  

code for problem3

import sun.rmi.runtime.Log;

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class RowGame { public long score(int[] board, int k) {
final int n = board.length; long[] lmax = new long[n];
for (int i = 0; i < n; ++ i) {
lmax[i] = Long.MIN_VALUE;
long s = 0;
for (int j = i; j >= 0; --j) {
s += board[j];
lmax[i] = Math.max(lmax[i], s);
}
} long[] minTimes = new long[n];
long[] maxScore = new long[n];
long tmp = 0;
for (int i = 0; i < n; ++i) {
minTimes[i] = Long.MAX_VALUE;
tmp += board[i];
if (tmp >= 0) {
minTimes[i] = 1;
maxScore[i] = tmp;
}
} long result = 0;
for (int i = 0; i < n; ++i) {
if (minTimes[i] > k) {
continue;
}
result = Math.max(result, maxScore[i] + lmax[i] * (k - minTimes[i]));
if (lmax[i] <= 0) {
continue;
}
tmp = maxScore[i];
for (int j = i + 1; j < n; ++j) {
tmp += board[j];
long t = (- tmp + 2 * lmax[i] - 1)/(2 * lmax[i]);
if ( t <= 0) {
t = 1;
}
long newTimes = minTimes[i] + t * 2;
long newScore = tmp + lmax[i] * t * 2;
if (minTimes[j] > newTimes || minTimes[j] == newTimes && maxScore[j] < newScore) {
minTimes[j] = newTimes;
maxScore[j] = newScore;
}
}
}
return result;
}
}

  

topcoder srm 450 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 682 Div1 Problem 450 SuccessfulMerger (环套树 + 分类讨论)

    题意  给定一个$n$个点$n$条边的无向图,现在要把这个图进行若干次操作,并选择一个点作为首都. 要求除首都外的任意两个点$u$, $v$,从$u$走到$v$必须经过这个首都. 操作为合并两个相邻的 ...

  4. topcoder srm 714 div1

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

  5. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

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

  6. Topcoder SRM 605 div1 题解

    日常打卡- Easy(250pts): 题目大意:你有n种汉堡包(统统吃掉-),每一种汉堡包有一个type值和一个taste值,你现在要吃掉若干个汉堡包,使得它们taste的总和*(不同的type值的 ...

  7. Topcoder SRM 602 div1题解

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

  8. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

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

  9. Topcoder SRM 584 DIV1 600

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

随机推荐

  1. 4.后台管理系统中的ajax提交或保存的两次模态框确认

    $(function () {         $('.ajaxForm').ajaxForm({         beforeSubmit:showPleaseWait,//提交之前        ...

  2. ssdb使用笔记

    ssdb是一款类似于redis的nosql数据库,不过redis是基于内存的,服务器比较昂贵,ssdb则是基于硬盘存储的,很容易扩展,对于一些对速度要求不是太高的应用,还是不错的选择. 先记录一个比较 ...

  3. LeetCode155.最小栈

    设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素. top() -- 获取栈顶元素. ...

  4. ReentrantLock源码(二)

    一.ReentrantLock类中的方法解读. 1.lock方法.实现了接口Lock中的lock方法.这里实际上是调用了sync成员变量的lock方法来实现.所以取决于sync的实现. 2.unloc ...

  5. tcl脚本

    tcl,全名tool command language,是一种通用的工具语言. 1)每个命令之间,通过换行符或者分号隔开: 2)tcl的每个命令包含一个或者多个单词,默认第一个单词表示命令,第二个单词 ...

  6. report源码分析——report_handle和report_server和report_catcher

    report_handle主要实现对message的action,severity,file的设置,然后将message传递给server: 主要的function有两个:initial和proces ...

  7. sublime text3 增加代码片段(snipper)

    有时候编写代码时有些代码片段经常会用到,如果能将这些代码片段整理,再在需要的时候通过某些条件触发,那无疑是非常方便的! 创建方法:工具->插件开发->新建代码片段 默认产生的内容是: &l ...

  8. git分支流

    ## 新建一个iss1分支 $ git branch iss1 ## 切换到iss1分支 $ git checkout iss1 Switched to branch 'iss1' ## 查看分支,当 ...

  9. kalinux 换源

    1.系统使用第一步建议先换源,否则将出现很多未知问题 #以下两个2选1,打开要编辑的源 sudo leafpad /etc/apt/sources.list sudo gedit /etc/apt/s ...

  10. Jmeter下进行ip伪造

    转至https://blog.csdn.net/xingchao416/article/details/53506051 1.首先获取一些闲置的ip地址,且必须为固定地址,不能是自动获取的地址,方法: ...