div1 250pt:

  题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵。

  解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新答案。

 // BEGIN CUT HERE

 // END CUT HERE
#line 5 "TheMatrix.cpp"
#include<cstdio>
#include<sstream>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cassert>
#include<iostream>
#include<string>
#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 TheMatrix
{
public:
bool check(vector<string>& s,int start,int end,int row){
for(int i = start + ;i <=end;i++)
if(s[row][i]==s[row][i-])return false;
return true;
}
bool ok(vector<string>& s,int start,int end,int row){
for(int i=start;i<=end;i++)
if(s[row][i]==s[row-][i])return false;
return true;
}
int MaxArea(vector <string> s){
//$CARETPOSITION$
int answer = ;
int n=s.size(),m=s[].size();
for(int i=;i<m;i++)
for(int j=;j<m;j++){
int down=,up=;
for(down=;down<n;down++){
if(check(s,i,j,down)){
up=down+;
while(up<n&&ok(s,i,j,up))up++;
int area=(j-i+)*(up-down);
answer=max(answer,area);
down=up-;
}
}
}
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(); if ((Case == -) || (Case == )) test_case_7(); }
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[] = {"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_1() { string Arr0[] = {""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_2() { string Arr0[] = {""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_3() { string Arr0[] = {"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_4() { string Arr0[] = {""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_5() { string Arr0[] = {"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_6() { string Arr0[] = {"",
"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); }
void test_case_7() { string Arr0[] = {"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, MaxArea(Arg0)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
TheMatrix ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

250pt

div1 500pt:

  题意:有个人有个飞机,起初有F升油,有很多个任务,第i个任务消耗duration[i]油,完成之后得到refuel[i]升油,求最多能完成的任务数。

  解法:先按照refuel降序排列,然后背包。

    why?

    对于两个任务,refuel大的在前面做一定要优于在后面做。假设现在剩余F升油,有两个任务a,b,其中duration[a] > duration[b],如果a先做,那么做完之后会剩余F - duration[a] + refuel[a]升油,如果b先做,会剩余F - duration[b] + refuel[b]升油,也就是说,如果两个都能做完的话,至少要保证F-duration[a]-duraion[b]+refuel[a/b]>=0,

显然先做refuel大的更可能完成。

  

 // BEGIN CUT HERE

 // END CUT HERE
#line 5 "AlbertoTheAviator.cpp"
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<sstream>
#include<cassert>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int dp[][];
pii hs[];
bool cmp(pii a,pii b){
return a.first > b.first;
}
class AlbertoTheAviator
{
public:
int MaximumFlights(int F, vector <int> duration, vector <int> refuel){
//$CARETPOSITION$
int n = duration.size();
for(int i = ;i < n;i++){
hs[i].first = refuel[i];
hs[i].second = duration[i];
}
sort(hs,hs+n,cmp);
memset(dp,-,sizeof(dp));
dp[][F] = ;
for(int i = ;i < n;i++){
for(int j=;j<=;j++)dp[i+][j]=dp[i][j];
for(int j=hs[i].second;j <= ;j++){
if(dp[i][j] == -)continue;
dp[i+][j-hs[i].second+hs[i].first]=max(dp[i+][j-hs[i].second+hs[i].first],dp[i][j]+);
}
} int answer = ;
for(int i = ;i <= ;i++)
answer = max(answer,dp[n][i]);
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() { int Arg0 = ; int Arr1[] = {}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arr2[] = {}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; verify_case(, Arg3, MaximumFlights(Arg0, Arg1, Arg2)); }
void test_case_1() { int Arg0 = ; int Arr1[] = {, }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arr2[] = {, }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; verify_case(, Arg3, MaximumFlights(Arg0, Arg1, Arg2)); }
void test_case_2() { int Arg0 = ; int Arr1[] = {, , , }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arr2[] = {, , , }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; verify_case(, Arg3, MaximumFlights(Arg0, Arg1, Arg2)); }
void test_case_3() { int Arg0 = ; int Arr1[] = {, }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arr2[] = {, }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; verify_case(, Arg3, MaximumFlights(Arg0, Arg1, Arg2)); }
void test_case_4() { int Arg0 = ; int Arr1[] = {}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arr2[] = {}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; verify_case(, Arg3, MaximumFlights(Arg0, Arg1, Arg2)); }
void test_case_5() { int Arg0 = ; int Arr1[] = {, , , , , , , , , , , , , }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arr2[] = {, , , , , , , , , , , , , }; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; verify_case(, Arg3, MaximumFlights(Arg0, Arg1, Arg2)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
AlbertoTheAviator ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

500pt

  

topcoder srm 610的更多相关文章

  1. topcoder SRM 610 DIV2 TheMatrix

    题目的意思是给一个01的字符串数组,让你去求解满足棋盘条件的最大棋盘 棋盘的条件是: 相邻元素的值不能相同 此题有点像求全1的最大子矩阵,当时求全1的最大子矩阵是用直方图求解的 本题可以利用直方图求解 ...

  2. topcoder SRM 610 DIV2 DivideByZero

    题目的意思是给你一组数,然后不断的进行除法(注意是大数除以小数),然后将得到的结果加入这组数种然后继续进行除法, 直到没有新添加的数为止 此题按照提议模拟即可 注意要保持元素的不同 int Count ...

  3. topcoder srm 610 div2 250

    第一次做tc 的比赛,一点也不懂,虽然题目做出来了, 但是,也没有在比赛的时候提交成功.. 还有,感谢一宁对tc使用的讲解.. 贴一下代码..... #include <cstring> ...

  4. topcoder srm 610 div1

    problem1 link 计算每个格子向上的最大高度.然后每个格子同一行前面的格子以及当前格子作为选取的矩形的最后一行,计算面积并更新答案. problem2 link 对于两个数据$(x_{1}, ...

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

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

  6. Topcoder SRM 643 Div1 250<peter_pan>

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

  7. Topcoder Srm 726 Div1 Hard

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

  8. TopCoder SRM 667 Div.2题解

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

  9. Topcoder Srm 673 Div2 1000 BearPermutations2

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

随机推荐

  1. Kubernetes 架构(下)【转】

    上一节我们讨论了 Kubernetes 架构 Master 上运行的服务,本节讨论 Node 节点. Node 是 Pod 运行的地方,Kubernetes 支持 Docker.rkt 等容器 Run ...

  2. PYTHON_DAY_02

    今日内容: 01 列表内置方法 '''''' ''' 列表: 定义: 在[]内,可以存放多个任意类型的值, 并以逗号隔开. 一般用于存放学生的爱好,课堂的周期等等... ''' # 定义一个学生列表, ...

  3. sed替换字符串中的某些字符

    test.txt原文内容 http://jsldfjaslfjsldfjasl/test?jlsdfjsalfjslfd 使用sed替换 sed -ri 's/(http:\/\/)[^\/]*(\/ ...

  4. strong&weak

    copy:建立一个索引计数为1的对象,然后释放旧对象 对NSString对NSString 它指出,在赋值时使用传入值的一份拷贝.拷贝工作由copy方法执行,此属性只对那些实行了NSCopying协议 ...

  5. JS简单实现防抖和节流

    一.什么是防抖和节流 Ps: 比如搜索框,用户在输入的时候使用change事件去调用搜索,如果用户每一次输入都去搜索的话,那得消耗多大的服务器资源,即使你的服务器资源很强大,也不带这么玩的. 1. 防 ...

  6. 客户端和服务器最多能发送和接收多少TCP连接数?

    1. 对于服务器,每一个tcp连接都要占一个文件描述符,一旦这个文件描述符使用完了,就会返回错误. 我们知道操作系统上端口号1024以下是系统保留的,从1024-65535是用户使用的.由于每个TCP ...

  7. [LUOGU] P2704 炮兵阵地

    题目描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队. 一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示), 也可能是平原(用"P&q ...

  8. 【集合遍历-Java】

    遍历List集合的三种方法 1.增强for循环 for(String str : list) {//其内部实质上还是调用了迭代器遍历方式,这种循环方式还有其他限制,不建议使用. System.out. ...

  9. Python爬虫-爬取京东商品信息-按给定关键词

    目的:按给定关键词爬取京东商品信息,并保存至mongodb. 字段:title.url.store.store_url.item_id.price.comments_count.comments 工具 ...

  10. LeetCode(27)Remove Element

    题目 Given an array and a value, remove all instances of that value in place and return the new length ...