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 ...
随机推荐
- 1.1 Qt入门
学习Qt的前提是学好C++. 我刚入门Qt,打算趁着暑假2个月时间来学习<C++ GUI Qt 4>这本书. 现在有Qt4和Qt5,似乎很多公司都还是在使用Qt4,所以我也就选择了学习Qt ...
- python爬虫---从零开始(四)BeautifulSoup库
BeautifulSoup是什么? BeautifulSoup是一个网页解析库,相比urllib.Requests要更加灵活和方便,处理高校,支持多种解析器. 利用它不用编写正则表达式即可方便地实现网 ...
- Hibernate5.x版本HQL限定查询 Legacy-style query parameters (`?`) are no longer supported
在此版本的限定查询和4.0版本的限定查询: 如果查询语句是: String hql = "select u from User u where u.gender = ?"; 会出现 ...
- No-3.Linux 终端命令格式
Linux 终端命令格式 01. 终端命令格式 command [-options] [parameter] 说明: command:命令名,相应功能的英文单词或单词的缩写 [-options]:选项 ...
- vue 点击按钮弹窗,点击关闭按钮关闭弹窗。
<div @click="btnfc()">点击弹窗按钮</div> <div v-show="show"> <div ...
- 利用canvas写一个验证码小功能
刚刚开始接触canvas,写个验证码小功能练练手,实现效果图如下: 主要代码如下: html <!DOCTYPE html> <html lang="en"> ...
- 6 SQL 函数、谓词、CASE表达式
6 函数.谓词.CASE表达式 6-1 各种各样的函数 /* 所谓函数,就是输入某一值得到相应输出结果的功能.输入值称为参数(parameter),输出值称为返回值. 函数大致可以分为以下几种 : 算 ...
- Python之阻塞IO模型与非阻塞IO模型
Python之阻塞IO模型与非阻塞IO模型 IO模型 1 阻塞IO: 全程阻塞 2 非阻塞IO: 发送多次系统调用: 优点:wait for data时无阻塞 缺点:1 系统调用太多 2 数据不是实时 ...
- PS修图知识小结
PS修图知识小结 [1]人去除红眼. 1.用红眼工具,框选红眼不分. 2.用椭圆选区工具,选择红眼部分 3..创建调整图层,亮度.对比度.加大对比度. 4.选择红眼部分.创建调整图层,可选颜色,减 ...
- 关于 HTTP meta 的 IE=edge 说明
http://www.oschina.net/question/54100_17414 陌生标记标记一: < meta http-equiv = "X-UA-Compatible&qu ...