topcoder srm 552
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的更多相关文章
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- 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 667 Div.2题解
概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- [topcoder]SRM 646 DIV 2
第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...
- [topcoder]SRM 633 DIV 2
第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...
- TopCoder<SRM>上的一道1100分的题目解析附代码
首先我们来简单看一下这道题的statement Problem Statement Note that in the following problem statement, all quo ...
随机推荐
- Maven实战读书笔记(四):Maven生命周期与插件
Maven的生命周期是对所有构建过程的抽象和统一.包含了项目的清理.初始化.编译.测试.打包.集成测试.验证.部署和站点生成等几乎所有构建步骤. Maven的生命周期是抽象的,其实际行为是由插件来完成 ...
- 【mybatis】mybatis数据源源码剖析(JNDI、POOLED、UNPOOLED)
一.概述 二.创建 mybatis数据源的创建过程稍微有些曲折. 1. 数据源的创建过程: 2. mybatis支持哪些数据源,也就是dataSource标签的type属性可以写哪些合法的参数? 弄清 ...
- 秋招复习-C++(二)
1.Segmentation Fault是什么?什么情况下会导致它的出现?怎么解决? Segmentation Fault中文是段错误,在Linux系统中,段错误一般是是由用户程序非法访问内存引起的( ...
- FastNet C++/Python 网络通信库之 协议
协议可以使用的基础数据类型: UInt8,UInt16,UInt32,UInt64Int8,Int16,Int32,Int64Float,Double,Bool,String [T] 数组,T代表元 ...
- [模板] Exgcd
求解一组ax+bc=gcd(a,b) #include<iostream> #include<cstdio> using namespace std; int exgcd(in ...
- redis搭建配置
1 .去官方下载 2.解压tar 3.进入解压目录 编译 4.将编译好的目录移动到制定位置.做软连接 .配置环境便利 5.创建数据保存目录.创建配置文件 [root@radis ~]# vim /da ...
- POJ 2631 Roads in the North (树的直径)
题意: 给定一棵树, 求树的直径. 分析: 两种方法: 1.两次bfs, 第一次求出最远的点, 第二次求该点的最远距离就是直径. 2.同hdu2196的第一次dfs, 求出每个节点到子树的最长距离和次 ...
- zoj 2857 Image Transformation
Image Transformation Time Limit: 2 Seconds Memory Limit: 65536 KB The image stored on a compute ...
- 《Shell脚本学习指南》书籍目录
摘要:Shell脚本与Windows/Dos下的批处理相似,也就是用各类命令预先放入到一个文件中,方便一次性执行的一个程序文件,主要是方便管理员进行设置或者管理用的.但是它比Windows下的批处理更 ...
- BZOJ:[JSOI2009]游戏Game【二分图匹配乱搞】
题目大意:n*m的棋盘,其中有些区域是禁区,两个人在棋盘上进行博弈,后手选择棋子的初始位置,然后先后手轮流将棋子往上下左右移动,走过的区域不能再走,问能否有一个位置使得后手必胜 Input 输入数据首 ...