topcoder srm 450 div1
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的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- TopCoder SRM 682 Div1 Problem 450 SuccessfulMerger (环套树 + 分类讨论)
题意 给定一个$n$个点$n$条边的无向图,现在要把这个图进行若干次操作,并选择一个点作为首都. 要求除首都外的任意两个点$u$, $v$,从$u$走到$v$必须经过这个首都. 操作为合并两个相邻的 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 605 div1 题解
日常打卡- Easy(250pts): 题目大意:你有n种汉堡包(统统吃掉-),每一种汉堡包有一个type值和一个taste值,你现在要吃掉若干个汉堡包,使得它们taste的总和*(不同的type值的 ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
随机推荐
- obv15 案例4,待日后分析
obv
- vue-lazyload的使用
1.下载依赖 npm install vue-lazyload --save 2.引入 import Vue from 'vue' import App from '@/App' import Vue ...
- jQuery-设计模式
[目录] 一.选择网页元素 二.改变结果集 三.链式操作 四.元素的操作:取值和赋值 五.元素的操作:移动 六.元素的操作:复制.删除和创建 七.工具方法 八.事件操作 九.特殊效果 [正文] 一.选 ...
- oauth2.0+app方式 webgis 授权
.认证方式有三种 Oauth2.0, Token-based http/windows 二.用户登录与应用登录区别 两者区别在于:当用户登录时,服务器端平台是否直接识别登录信息和验证登录信息. 应用登 ...
- C# & ASP.NET Core 入门官方资料汇总
借助给公司实习生培训事宜,整理了一些微软官方的适合新同学入门的资料,这里分享一下: 工具: Visual Studio 2017 Community 版本下载地址:https://www.visual ...
- SQL性能优化前期准备-清除缓存、开启IO统计
文章来至:https://www.cnblogs.com/Ren_Lei/p/5669662.html 如果需要进行SQl Server下的SQL性能优化,需要准备以下内容: 一.SQL查询分析器设置 ...
- ReactiveCocoa(II)
RAC类关系图: RAC 信号源: 需要导入的头文件: import ReactiveCocoa import Result import ReactiveSwift 冷信号 //1.冷信号 let ...
- python操作Mysql数据库示例
python库:pymysql 安装:install pymysql.mysql数据库 一.连接数据库.创建speder库.查询版本. import pymysql ##链接数据库 db = pymy ...
- java 的Colections类(Java也有python类似列表的反转、排序等方法)
1.Collections类概述 针对集合操作 的工具类,都是静态方法 2.Collections成员方法 public static <T> void ...
- ResourceBundle与Properties读取配置文件
ResourceBundle与Properties的区别在于ResourceBundle通常是用于国际化的属性配置文件读取,Properties则是一般的属性配置文件读取. ResourceBundl ...