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. codeforces 185A Plant(推公式)

    Plant [题目链接]Plant [题目类型]推公式 &题解: 这个是可以推公式的: 每年的总个数是4^n个,设n年时向上的个数是x个,向下的个数是y个,那么n+1年时,向上的个数是3* x ...

  2. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  3. java.lang.ClassNotFoundException: org.hibernate.engine.FilterDefinition的解决方案

    今天在GitHub上面看到一个有意思的项目,下载下来,使用tomcat部署失败,出现异常,网上说JDK版本太高,改低,还是失败. 由于本人有个习惯,更喜欢把项目直接放入tomcat webapps 里 ...

  4. Python记录8:函数的嵌套

    #函数的嵌套分为两类:# 1.函数的嵌套定义: 在函数内部又定义了一个函数# def foo():# x=1# # print(x)# def bar():# print('from bar')## ...

  5. Linux 命令整理-tailf

    1.tailf 跟踪日志文件 常用参数格式: tailf -n logfile 动态跟踪日志文件logfile,最初的时候打印文件的最后10行内容. 实例 查看从倒数多少行的日志信息 2.tail 跟 ...

  6. mac快捷键留存查看

    基本的快捷键 Command是Mac里最重要的修饰键,在大多数情况下相当于Windows下的Ctrl.所以以下最基本操作很好理解: Command-Z 撤销 Command-X 剪切 Command- ...

  7. <6>Cocos Creator​​​​​​​调试

    高手在于调试,下面来谈Cocos Creator调试! 1. 网页平台调试 调试常见的三种形式为调试打印.运行时报错与断点调试,这里主要利用编辑器"VS Code"与"C ...

  8. rpgmakermv(10) GraphicalDesignMode

    插件地址:https://github.com/triacontane/RPGMakerMV/blob/master/GraphicalDesignMode.js 原文: メニュー画面や戦闘画面など各 ...

  9. Vim for Windows --ctags

    What is ctags? ctags -- Generate tag files for source code,which is a tool used for facilitating rea ...

  10. 20165316 技能学习心得与c语言学习

    20165316 技能学习心得与c语言学习 一.技能学习经验 我会打乒乓球,在中国,我只能说我"会"打,至于"比大多数人更好"我不敢断言,因为我无时无刻不感受到 ...