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& ...
随机推荐
- webpack使用七
产品阶段的构建 目前为止,我们已经使用webpack构建了一个完整的开发环境.但是在产品阶段,可能还需要对打包的文件进行额外的处理,比如说优化,压缩,缓存以及分离CSS和JS. 对于复杂的项目来说,需 ...
- bzoj 2308 小Z的袜子(莫队算法)
小Z的袜子 [题目链接]小Z的袜子 [题目类型]莫队算法 &题解: 莫队算法第一题吧,建议先看这个理解算法,之后在参考这个就可以写出简洁的代码 我的比第2个少了一次sort,他的跑了1600m ...
- jquery $.ajax $.get $.post的区别?
$.ajax 是 jQuery 底层 AJAX 实现,$.ajax是一种通用的底层封装,$.ajax()请求数据之后,则需要使用回调函数,有beforeSend.error.dataFilter.su ...
- JS实例5
做这么一个效果 鼠标单击某个名字后变色,没选中的鼠标移动上去变色 首先布局这个效果,然后给每个表格添加单击事件onclick.鼠标放上事件onmousemove.鼠标移出事件onmouseout 容 ...
- Beta阶段冲刺前计划与安排
凡事预则立,在Beta开始前,以小组为单位,在敏捷冲刺前发布一篇博客,描述: 1. 介绍小组新加入的成员,Ta担任的角色. 新加入的成员是丁蓉同学,在本团队中担任前端设计. 原因:在之前的团队中,她就 ...
- IIS8无法通过IP访问解决办法
今天配置在Windows server 2012 R2 上配置IIS8时,出现局域网内无法使用IP访问站点的问题,查找资料依然无法解决.最后发现IIS8配置好主机名后无法使用主机IP访问站点,只能使用 ...
- 【转】robotFramework 与testlink集成
场景: robotframework 执行完用例之后,将执行结果报至testlink. 方案1: 通过TestLink-API-Python-client中的RF关键字 每条用例执行完成之后根据状态进 ...
- Spark学习之路 (二十八)分布式图计算系统
一.引言 在了解GraphX之前,需要先了解关于通用的分布式图计算框架的两个常见问题:图存储模式和图计算模式. 二.图存储模式 巨型图的存储总体上有边分割和点分割两种存储方式.2013年,GraphL ...
- Runtime单例模式类 -- 控制电脑关机
package demo1; import java.io.IOException; public class RunTimeDemo { public static void main(String ...
- nginx tomcat https
.首先确保机器上安装了openssl和openssl-devel #yum install openssl #yum install openssl-devel . server { listen s ...