div1 250pt:

  题意:用RGB三种颜色的球摆N层的三角形,要求相邻的不同色,给出RGB的数量,问最多能摆几个

  解法:三种颜色的数量要么是全一样,要么是两个一样,另外一个比他们多一个,于是可以分类讨论:对于数量全一样的,直接算;对于另外的,我们可以先不考虑多出来的那一个,也是正常放,然后看最后剩下的位置能不能放完所有多出来的那一个,这个可以二分。

 // BEGIN CUT HERE

 // END CUT HERE
#line 5 "FoxPaintingBalls.cpp"
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cassert>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
class FoxPaintingBalls
{
public:
long long theMax(long long R, long long G, long long B, int N){
//$CARETPOSITION$
if(N == )return R+G+B;
ll total = 1LL*N*(N + ) / ;
ll least = total / ;
ll maxn = min(min(R,G),B) / least;
if(total % == )return maxn;
ll answer = ,left = ,right = maxn;
while(left <= right){
// cout << "L: "<<l<<" R: "<<r<<endl;
ll mid = (left + right) >> ;
ll r = R - mid * least,g = G - mid * least,b = B - mid * least;
if((r + g + b) >= mid){
answer = mid;
left = mid + ;
}else{
right = mid - ;
}
}
return answer; } // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); if ((Case == -) || (Case == )) test_case_5(); if ((Case == -) || (Case == )) test_case_6(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { long long Arg0 = 2LL; long long Arg1 = 2LL; long long Arg2 = 2LL; int Arg3 = ; long long Arg4 = 1LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
void test_case_1() { long long Arg0 = 1LL; long long Arg1 = 2LL; long long Arg2 = 3LL; int Arg3 = ; long long Arg4 = 0LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
void test_case_2() { long long Arg0 = 8LL; long long Arg1 = 6LL; long long Arg2 = 6LL; int Arg3 = ; long long Arg4 = 2LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
void test_case_3() { long long Arg0 = 7LL; long long Arg1 = 6LL; long long Arg2 = 7LL; int Arg3 = ; long long Arg4 = 2LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
void test_case_4() { long long Arg0 = 100LL; long long Arg1 = 100LL; long long Arg2 = 100LL; int Arg3 = ; long long Arg4 = 30LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
void test_case_5() { long long Arg0 = 19330428391852493LL; long long Arg1 = 48815737582834113LL; long long Arg2 = 11451481019198930LL; int Arg3 = ; long long Arg4 = 5750952686LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); }
void test_case_6() { long long Arg0 = 1LL; long long Arg1 = 1LL; long long Arg2 = 1LL; int Arg3 = ; long long Arg4 = 3LL; verify_case(, Arg4, theMax(Arg0, Arg1, Arg2, Arg3)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
FoxPaintingBalls ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

250pt

div 500pt:

  题意:N*N的格子里有两种颜色的花,L,P给出一个maxDiff,要求找出来两个不相交的矩形,使得他们两个中L,P的数量之差<=maxDiff,并且数量最多

  解法:枚举分割线,然后预处理,L[i][j]表示i条线左侧差为j的最大数量,其余同理,最后枚举算一下。

 // BEGIN CUT HERE

 // END CUT HERE
#line 5 "FoxAndFlowerShopDivOne.cpp"
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cassert>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = ;
inline void checkmax(int &a,int b){
if(a == - || a < b)a = b;
}
int L[N][N*N*],R[N][N*N*],U[N][N*N*],D[N][N*N*];
class FoxAndFlowerShopDivOne
{
public:
int theMaxFlowers(vector <string> flowers, int maxDiff){
//$CARETPOSITION$
memset(L,-,sizeof(L));
memset(R,-,sizeof(R));
memset(U,-,sizeof(U));
memset(D,-,sizeof(D));
int n=flowers.size(),m=flowers[].size();
for(int top=;top<n;top++){
for(int bottom=top;bottom<n;bottom++){
for(int left=;left<m;left++){
for(int right=left;right<m;right++){
int total = ,d = ;
for(int i=top;i<=bottom;i++){
for(int j=left;j<=right;j++){
total += flowers[i][j]!='.';
d += flowers[i][j]=='L';
d -= flowers[i][j]=='P';
}
}
for(int i=right+;i<m;i++)
checkmax(L[i][d+n*m],total);
for(int i=left;i>=;i--)
checkmax(R[i][d+n*m],total);
for(int i=bottom+;i<n;i++)
checkmax(U[i][d+n*m],total);
for(int i=top;i>=;i--)
checkmax(D[i][d+n*m],total);
}
}
}
}
int answer = -;
for(int i=;i<n;i++){
for(int j=;j<=n*m*;j++){
for(int k=;k<=n*m*;k++){
if(abs(j+k-n*m*)<=maxDiff && U[i][j]!=- && D[i][k] !=-)
checkmax(answer,U[i][j]+D[i][k]);
}
}
}
for(int i=;i<m;i++){
for(int j=;j<=n*m*;j++){
for(int k=;k<n*m*;k++){
if(abs(j+k-n*m*)<=maxDiff && L[i][j] != - && R[i][k] != -)
checkmax(answer,L[i][j]+R[i][k]);
}
}
}
return answer;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); if ((Case == -) || (Case == )) test_case_5(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { string Arr0[] = {"LLL",
"PPP",
"LLL"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, theMaxFlowers(Arg0, Arg1)); }
void test_case_1() { string Arr0[] = {"LLL",
"PPP",
"LLL"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, theMaxFlowers(Arg0, Arg1)); }
void test_case_2() { string Arr0[] = {"...",
"...",
"..."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, theMaxFlowers(Arg0, Arg1)); }
void test_case_3() { string Arr0[] = {"LLPL.LPP",
"PLPPPPLL",
"L.P.PLLL",
"LPL.PP.L",
".LLL.P.L",
"PPLP..PL"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, theMaxFlowers(Arg0, Arg1)); }
void test_case_4() { string Arr0[] = {"LLLLLLLLLL",
"LLLLLLLLLL",
"LLLLLLLLLL",
"LLLLLLLLLL",
"LLLLLLLLLL"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = -; verify_case(, Arg2, theMaxFlowers(Arg0, Arg1)); }
void test_case_5() { string Arr0[] = {"LLLP..LLP.PLL.LL..LP",
"L.PL.L.LLLL.LPLLPLP.",
"PLL.LL.LLL..PL...L..",
".LPPP.PPPLLLLPLP..PP",
"LP.P.PPL.L...P.L.LLL",
"L..LPLPP.PP...PPPL..",
"PP.PLLL.LL...LP..LP.",
"PL...P.PPPL..PLP.L..",
"P.PPPLPLP.LL.L.LLLPL",
"PLLPLLP.LLL.P..P.LPL",
"..LLLPLPPPLP.P.LP.LL",
"..LP..L..LLPPP.LL.LP",
"LPLL.PLLPPLP...LL..P",
"LL.....PLL.PLL.P....",
"LLL...LPPPPL.PL...PP",
".PLPLLLLP.LPP...L...",
"LL...L.LL.LLLPLPPPP.",
"PLPLLLL..LP.LLPLLLL.",
"PP.PLL..L..LLLPPL..P",
".LLPL.P.PP.P.L.PLPLL"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; int Arg2 = ; verify_case(, Arg2, theMaxFlowers(Arg0, Arg1)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
FoxAndFlowerShopDivOne ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

500pt

topcoder srm 552的更多相关文章

  1. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  3. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  4. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  5. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  6. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  7. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  8. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

  9. TopCoder<SRM>上的一道1100分的题目解析附代码

    首先我们来简单看一下这道题的statement Problem Statement      Note that in the following problem statement, all quo ...

随机推荐

  1. CAD交互绘制直线(网页版)

    用户可以在CAD控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE ...

  2. spring mvc poi excel

    Util类 package com.common.util; public class ExportUtil { private XSSFWorkbook wb = null; private XSS ...

  3. sql数据表的设计思路

    好的表结构分的比较细致,个人理解大概主要分为主表.明细.历史记录表.中间表,辅助表结构应该分为:类型表.状态表.统计表.统计明细表等.为了一个功能加那么多表实在是多余,如果写一个非常复杂的业务逻辑还是 ...

  4. (12) OpenSSL主配置文件openssl.cnf

    1.man config 该帮助文档说明了openssl.cnf以及一些其他辅助配置文件的规范.格式及读取方式.后文中的所有解释除非特别指明,都将以openssl.cnf为例. [root@local ...

  5. SANBA服务和FTP服务

    1.samba服务 Smb主要作为网络通信协议:Smb是基于cs(client/server)架构(架构还有bs,broswer/server):完成linux与windows之间的共享:linux与 ...

  6. Linux基础测试

    目 录 第1章 文件及目录课后作业    1 第2章 Linux打包与压缩习题    1 第3章 Linux系统VIM编辑器习题    1   文件及目录课后作业 从/proc/meminfo中过滤出 ...

  7. 如何用纯 CSS 创作一种侧立图书的特效

    效果预览 在线演示 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/deVgRM 可交互视频教程 此视 ...

  8. python基础知识10-描述器和装饰器

    课前的解答 1.vim怎么退出都知道吧,配置了pep8,所以说会出现退出的时候error,再退出一次就ok q:退出 w:保存 wq 保存退出 q!:强制退出 shift + zz:保存退出 x:保存 ...

  9. python抓取知识星球精选帖,制作为pdf文件

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/90 背景: 这两年知识付费越来越热,我也加入了不少知识星球 ...

  10. my97datepicker插件日期值改变事件 等同于input的onchang()时间

    官网Demo地址http://www.my97.net/demo/index.htm <input type="text" class="Wdate" v ...