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. gitlab 源码安装=》rpm安装横向迁移(version 9.0)

    准备: 下载版本地址: https://packages.gitlab.com/gitlab/gitlab-ce 迁移环境: 源码安装的gitlab9.0.13 目标迁移至9.0.13 RPM安装的环 ...

  2. 21Oracle数据库和实例

    Oracle数据库:相关的操作系统文件(即储存在计算机硬盘上的文件)的集合,这些文件组织在一起,成为一个逻辑整体,即为Oracle数据库.物理存在 Oracle实例:位于物理内存里的数据结构,它由操作 ...

  3. JavaScript-模拟收银台小程序

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. Django MTV模式详解

      出自:http://blog.csdn.net/dbanote/article/details/11338953 在正式开始coding之前,我觉得有必要探讨下Django的MTV模式,理论和实践 ...

  5. kettle杂记

    版本8.0,以下是我在使用kettle时候的一些小tips 1.“插入/更新”必须指定字段,“表输出”无需指定字段,但是源表的字段必须包含在目标表中,否则unknown colum! 2.连接数据库时 ...

  6. map 的用法

    #include<iostream> #include<map> #include<string> #define s second #define f first ...

  7. hdu5371 manacher + 线段树

    这题说的找出一个数组串 3等分 第一个部分和第3个部分一样,第二个部分和第一个部分回文,那么计算出这些字符串问这样的字符串最长为多少,我们先使用manacher 计算出每个位置以他为对称轴左边端点的最 ...

  8. sitecore系统教程之体验编辑器中创建一个项目

    您可以使用体验编辑器创建新项目并将其直接插入网页. 注意 如何在Sitecore中创建项目可能会有所不同,具体取决于您拥有的安全角色以及网站的设置方式. 要插入新项目: 在体验编辑器中,导航到要添加新 ...

  9. STL容器之set

    [1]set容器 一个集合(set)是一个容器,它其中所包含的元素的值是唯一的. [2]set容器方法 (1)set构造函数.插入函数.遍历过程 应用示例代码如下: #include <set& ...

  10. python pprint

    使用 pprint 模块 pprint 模块( pretty printer ) 用于打印 Python 数据结构. 当你在命令行下打印特定数据结构时你会发现它很有用(输出格式比较整齐, 便于阅读). ...