设horns和hoofs的数量分别为 x 和 y ,题目要求:

满足 x+y <= K,使得A*x + B*y - x*x - y*y 最大。

枚举 i 从0~K,直接解方程得对称轴 x = ( 2*i + A - B ) / 4,判断对称轴是否在 [ 0, i ] 区间内。

注意:

1.精度

2.x需要上下个取整一次

3.如果最大值都<=0,那么最大收益直接为 0 即可。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm> const double eps = 1e-;
const double INF = 1e10; using namespace std; double A, B;
int N; int dcmp( double a )
{
if ( fabs(a) < eps ) return ;
return a < ? - : ;
} double cal( int x, int y )
{
return A*x + B*y -x*x - y*y;
} int main()
{
while ( ~scanf( "%lf%lf", &A, &B ) )
{
scanf( "%d", &N );
double ans = -INF;
int ansX, ansY; for ( int i = ; i <= N; ++i )
{
int tmp = floor(( * i + A - B ) / 4.0) ;
if ( tmp < ) tmp = ;
else if ( tmp > i ) tmp = i; double tmpcal = cal( tmp, i - tmp );
if ( dcmp( ans - tmpcal ) < )
{
ans = tmpcal;
ansX = tmp;
ansY = i - tmp;
}
else if ( dcmp( ans - tmpcal ) == )
{
if ( tmp < ansX )
{
ansX = tmp;
ansY = i - tmp;
}
else if ( tmp == ansX )
{
if ( ansY > i - tmp )
{
ansY = i - tmp;
}
}
} tmp = ceil( ( * i + A - B ) / 4.0 ) ; if ( tmp < ) tmp = ;
else if ( tmp > i ) tmp = i; tmpcal = cal( tmp, i - tmp );
if ( dcmp( ans - tmpcal ) < )
{
ans = tmpcal;
ansX = tmp;
ansY = i - ansX;
}
else if ( dcmp( ans - tmpcal ) == )
{
if ( tmp < ansX )
{
ansX = tmp;
ansY = i - tmp;
}
else if ( tmp == ansX )
{
if ( ansY > i - tmp )
{
ansY = i - tmp;
}
}
}
} if ( dcmp(ans) <= || ( ansX <= && ansY <= ) )
{
puts("0.00");
puts("0 0");
continue;
} printf( "%.2f\n", ans );
printf( "%d %d\n", ansX, ansY );
}
return ;
}

URAL 1200 Horns and Hoofs 枚举的更多相关文章

  1. URAL 2031. Overturned Numbers (枚举)

    2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...

  2. ural 1200

    推出公式  然后特判两端  代码其实挺烂      但是有人竟然可以直接暴过去的 ...... #include <cstdio> #include <cstring> #in ...

  3. ural1701 Ostap and Partners

    Ostap and Partners Time limit: 2.0 secondMemory limit: 64 MB Workman Ivan lost his job. Not because ...

  4. URAL 1792. Hamming Code (枚举)

    1792. Hamming Code Time limit: 1.0 second Memory limit: 64 MB Let us consider four disks intersectin ...

  5. 【折半枚举】Ural Championship April 30, 2017 Problem G. Glasses with solutions

    题意:有n杯盐溶液,给定每杯里面盐的质量以及盐溶液的质量.问你有多少种方案选择一个子集,使得集合里面的盐溶液倒到一个被子里面以后,浓度为A/B. 折半枚举,暴力搜索分界线一侧的答案数,跨越分界线的答案 ...

  6. 【枚举】URAL - 2081 - Faulty dial

    //._. ... ._. ._. ... ._. ._. ._. ._. ._. //|.| ..| ._| ._| |_| |_. |_. ..| |_| |_| //|_| ..| |_. ._ ...

  7. POJ 1200 字符串HASH

    题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有 ...

  8. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  9. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

随机推荐

  1. elasticsearch-查询的基本语法

    elasticsearch的查询有两部分组成:query and filter. 两者的主要区别在于:filter是不计算相关性的,同时可以cache.因此,filter速度要快于query. 先记录 ...

  2. Ruby 多线程探索实践与归纳总结

    Ruby 多线程 每个正在系统上运行的程序都是一个进程.每个进程包含一到多个线程. 线程是程序中一个单一的顺序控制流程,在单个程序中同时运行多个线程完成不同的工作,称为多线程. Ruby 中我们可以通 ...

  3. android开发 drawtext的开始坐标位置

    我们canvas绘制文字的遇到一个不知道drawtext(str,x,y,paint)  中的x.y坐标值怎么定义,,如果设为(0,0)的话文字就不会出来了.因此查找到一下资料: 问:canvas.d ...

  4. 22、DDMS(转载)

    本文是转载,出处为http://www.xuebuyuan.com/1291595.html 如需删除本文,请私信我,谢谢 DDMS DDMS是一款Google* 提供的应用,可作为独立的工具运行,也 ...

  5. hdu 3572 Task Schedule 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...

  6. BZOJ 2820 YY的GCD

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=2820 有种方法是枚举质数然后用BZOJ2301来做但是超时了... 具体式子大概张这样: ...

  7. maven ArtifactTransferException: Failure to transfer

    我在使用Myeclipse碰见这个错误,我没有用伺服,直接连接到maven中心. ArtifactTransferException: Failure to transfer org.apache.h ...

  8. Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. vector内存分配

    vector,map 这些容器还是在堆上分配的内存,在析构时是释放空间 vector在提高性能可以先reserve在push_back() reserve:决定capacity,但没有真正的分配内存, ...

  10. [百度空间] [原]DLL导出实例化的模板类

    因为模板是在编译的时候根据模板参数实例化的,实例化之后就像一个普通的类(函数),这样才有对应的二进制代码;否则,没有模板参数,那么编译器就不知道怎么生成代码,所以生成的DLL就没有办法导出模板了.但是 ...