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)其 ...
随机推荐
- C++ new运算符
new 分配的数据类型:内置数据类型.自定义数据类型. 如果不成功,则 new 将返回零或引发异常:编写自定义异常处理例程并调用 _set_new_handler运行库函数(以您的函数名称作为其参数) ...
- MyBatis基础入门《十九》动态SQL(set,trim)
MyBatis基础入门<十九>动态SQL(set,trim) 描述: 1. 问题 : 更新用户表数据时,若某个参数为null时,会导致更新错误 2. 分析: 正确结果: 若某个参数为nul ...
- LeetCode21.合并两个有序链表
将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1->2- ...
- docker-php-ext-install.md(https://gist.github.com/giansalex/2776a4206666d940d014792ab4700d80)
```bash RUN apt update RUN apt upgrade -y RUN apt install -y apt-utils RUN a2enmod rewrite RUN apt i ...
- ubuntu安装rvm
sudo apt-get install curl git-core bash -s stable < <(curl -s https://raw.github.com/wayneeseg ...
- Sitecore详细安装(包含sitecore安装过程截图)
一.到Sitecore 官网下载安装包 1)浏览器中输入https://dev.sitecore.net/Downloads/Sitecore_Experience_Platform.aspx 2)安 ...
- Chrome浏览器相关细节整理
一.上传文件卡死 可能时由于输入法的原因导致上传文件浏览器卡死.将输入法改为英文模式再操作上传文件就不会卡死了.
- bzoj3678 简单题
题目链接 bitset #include<algorithm> #include<iostream> #include<cstdlib> #include<c ...
- nfs共享文件搭建
Linux NFS服务器的安装与配置详解 一.NFS服务简介 NFS是Network File System(网络文件系统).主要功能是通过网络让不同的服务器之间可以共享文件或者目录.NFS客户端 ...
- QMenu 设置菜单图标 & 生成菜单树
效果图 源码 .h 文件 protected slots: void onMenuTriggered(QAction*); .cpp 文件 // 菜单 QMenu *pMenu = new QMenu ...