topcoder srm 380 div1
problem1 link
分类讨论。高度没有太大关系。主要看长度。
problem2 link
二分答案$mid$。计算每种$card$不足的部分,加起来,小于等于$min(jokers,mid)$就是合法的。
problem3 link
为了方便说明,以下所说的$x,y,a$分别是菱形宽度一半的平方、高度一半的平方、边长的平方。所以有$x+y=a$
对于宽的来说,比如第一个,$y_{1}\leq x_{1}$,所以$0\leq y_{1}\leq \frac{a_{1}}{2}$
对于高的来说,比如第二个,$y_{2}\geq x_{2}$,所以$ \frac{a_{2}}{2}\leq y_{1}\leq a_{2}$,宽和内部的高的关系为$y_{1}=y_{2}$,所以有$\frac{a_{2}}{2} \leq y_{1} \leq a_{2}$
同理对于第三个来说,它是宽的,所以$\frac{a_{3}}{2}\leq x_{3}\leq a_{3}$,高和内部的宽的关系为$x_{2}=x_{3}$,所以$\frac{a_{3}}{2}\leq x_{3}=x_{2}=a_{2}-y_{2}=a_{2}-y_{1}\leq a_{3}$,所以$a_{2}-a_{3} \leq y_{1} \leq a_{2}-\frac{a_{3}}{2}$
按照这个推导下去,会得到$y_{1}$的若干个区间,所有区间求交即可得到$y_{1}$最后的区间。如果区间合法,最小值就是答案。
code for problem1
import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class LameKnight { public int maxCells(int n,int m) {
if(n==1) {
return 1;
}
else if(n==2){
if(m>=7) {
return 4;
}
else if(m>=5) {
return 3;
}
else if(m>=3) {
return 2;
}
else {
return 1;
}
}
else {
if(m>=7) {
return 3+(m-5);
}
else {
int result=dfs(1,1,n,m);
if(result>4) {
result=4;
}
return result;
}
}
} int dfs(int x,int y,int n,int m) {
if(x<1||x>n||y<1||y>m) {
return 0;
}
int result=1;
result=Math.max(result,1+dfs(x+2,y+1,n,m));
result=Math.max(result,1+dfs(x+1,y+2,n,m));
result=Math.max(result,1+dfs(x-1,y+2,n,m));
result=Math.max(result,1+dfs(x-2,y+1,n,m));
return result;
}
}
code for problem2
import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class CompilingDecksWithJokers { public int maxCompleteDecks(int[] cards, int jokers) {
int low=0,high=1000000000;
int result=low;
while(low<=high) {
int mid=(low+high)>>1;
if(check(mid,cards,jokers)) {
result=Math.max(result,mid);
low=mid+1;
}
else {
high=mid-1;
}
}
return result;
} boolean check(int mid,int[] cards,int jokers) {
long result=0;
for(int i=0;i<cards.length&&result<=jokers&&result<=mid;++i) {
if(cards[i]<mid) {
result+=mid-cards[i];
}
}
return result<=jokers&&result<=mid;
}
}
code for problem3
import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class NestedDiamonds { public double minHeight(int[] sides) {
Arrays.sort(sides);
final int n=sides.length;
for(int i=1;i<n;++i) {
if(sides[i]==sides[i-1]) {
return -1;
}
}
long[] a=new long[n];
for(int i=0;i<n;++i) {
a[i]=(long)sides[n-1-i]*sides[n-1-i];
}
long low=0,high=a[0];
for(int i=1;i<n;++i) {
long newlow=0,newhigh=0;
int sign=1;
for(int j=1;j<i;++j) {
newlow+=sign*2*a[j];
newhigh+=sign*2*a[j];
sign*=-1;
}
if((i&1)==1) {
newlow+=a[i];
newhigh+=2*a[i];
}
else {
newlow-=2*a[i];
newhigh-=a[i];
}
low=Math.max(low,newlow);
high=Math.min(high,newhigh);
}
if(low>high) {
return -1;
}
return Math.sqrt(0.5*low)*2;
}
}
topcoder srm 380 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 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 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& ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
- topcoder srm 575 div1
problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...
随机推荐
- MySQL主从同步问题
1,The replication receiver thread cannot start because the master has GTID_MODE = OFF and this serve ...
- .net中ashx文件有什么用?功能有那些,一般用在什么情况下?
.ashx是“一般处理文件”.和aspx类似.但是这种文件要比aspx这种前台页面文件内容简单轻巧..ashx不提供前台展示的功能.也可以说它结合了.cs类文件而且又可以提供给.aspx文件做UI层的 ...
- memory consistency
目前的计算机系统中,都是shared memory结构,提供统一的控制接口给软件, shared memory结构中,为了memory correctness,可以将问题分为:memory consi ...
- (1)打造简单OS-汇编写入引导区,虚拟机启动步骤
首先需要您在网上下载NASM编译器,可以将汇编编译为二进制文件 1.写一段汇编代码在屏幕上打印一段字符,可以运行的!并进行nasm为二进制文件,如下"test.asm" 该段汇编主 ...
- table 的rolspan和rowspan
如图所示啦,容易让初学者混乱的两个东西仔细看看分析下呢,就比较简单了 <table width="300" border="2"> <tr&g ...
- workerman 7272端口被占用
1/问题:workerman 7272端口被占用 2/策略: 1.查找被占用的端口 netstat -tln netstat -tln | grep 8083 netstat -tln 查看端口使用情 ...
- 10 enumerate()在字典,列表中的用法详解
1.字典 li = {"alex"," aric","Alex","Tony","rain"}for ...
- CBV源码解析
1.CBV(class based view) 首先定义一个视图函数,用类的方式定义: 举例: class LoginView(View): def get(self,request): return ...
- flask模板应用-自定义错误页面
自定义错误页面 当程序返回错误响应时,会渲染一个默认的错误页面,我们可以注册错误处理函数来处理错误页面 错误处理函数和视图函数很相似,返回值将作为响应的主题,因此我们先要创建错误页面的模板文件.为了和 ...
- c# 使用checked和unchecked
首先要知道int型在c#中是一个32位的数.由此可以知道int型的取值范围是(-2147483648~2147483647)当要使用int的最小值或者是最大值的时候,可以使用int.MinValue和 ...