topcoder srm 550
div1 250pt:
题意:有个机器人,从某一点出发,他只有碰到地形边缘或者碰到走过的点时才会改变运动方向,然后接着走,现在给出他的运动轨迹,判断他的运动是否合法,如果合法的话,那么整个地形的最小面积是多少。
解法:先随便设定一个起点,然后模拟机器人走的路线,先确定出来运动的大致范围,然后判断运动轨迹是否合法,也就是出了最后一步可以手动终止之外,看其他的时候,它转变方向是不是合法。。。。
// BEGIN CUT HERE // END CUT HERE
#line 5 "RotatingBot.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;
int vis[][];
int dir[][] = {,,,,-,,,-};
class RotatingBot
{
public:
int minArea(vector <int> moves){
//$CARETPOSITION$
memset(vis,-,sizeof(vis));
int cur_d = ;
int cur_x = ,cur_y = ;
vis[cur_x][cur_y] = ;
for(int i = ;i < moves.size();i++){
int len = moves[i];
while(len > ){
cur_x += dir[cur_d][];
cur_y += dir[cur_d][];
if(vis[cur_x][cur_y] != -)return -;
vis[cur_x][cur_y] = i;
len --;
}
cur_d = (cur_d + ) % ;
}
// cout << "done" <<endl;
int left = ,right = ,top = ,bottom = ;
for(int i = ;i < ;i++)
for(int j = ;j < ;j++){
if(vis[i][j] != -){
left = min(left,i);
right = max(right,i);
top = max(top,j);
bottom = min(bottom,j);
}
}
// cout <<"left: "<<left<<" right: "<<right <<" top: "<<top<<" bottom:"<<bottom<<endl;
cur_x = ,cur_y = ;cur_d = ;
for(int i = ;i < moves.size();i++){
int len = moves[i];
while(len > ){
cur_x += dir[cur_d][];
cur_y += dir[cur_d][];
len --;
}
if(i == moves.size() - )continue;
int next_x = cur_x + dir[cur_d][];
int next_y = cur_y + dir[cur_d][];
if(next_x >= left && next_x <= right && next_y >= bottom && next_y <= top){
if(vis[next_x][next_y] == -)return -;
if(vis[next_x][next_y] > i)return -;
}
cur_d = (cur_d + ) % ;
}
return (right - left + ) * (top - bottom + ); } // 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() { int Arr0[] = {}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minArea(Arg0)); }
void test_case_1() { int Arr0[] = {,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minArea(Arg0)); }
void test_case_2() { int Arr0[] = {,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = -; verify_case(, Arg1, minArea(Arg0)); }
void test_case_3() { int Arr0[] = {,,,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minArea(Arg0)); }
void test_case_4() { int Arr0[] = {,,,,,,,,,,,,,,,,,,,,,,,,,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minArea(Arg0)); }
void test_case_5() { int Arr0[] = {,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = -; verify_case(, Arg1, minArea(Arg0)); }
void test_case_6() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minArea(Arg0)); }
void test_case_7() { int Arr0[] = {,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minArea(Arg0)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
RotatingBot ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
250pt
div1 500pt:
题意:两个人在一个无限大的格子里涂色,第一个人先在(0,0)涂色,然后接下来的每一轮,对于所有的点(x,y),如果(x-1,y-1)和(x-2,y)中有且只有一个点被涂色了,那么就把这个点也涂了,问经过t轮之后,某个区域的染色情况。
解法:先在纸上模拟一下前几轮的情况,我们很容易发现,被涂色的区域就是{x>=0,y>=0并且x<=y}这部分区域,而且被涂色点的分布很像一个杨辉三角,其中被涂色的部分就是杨辉三角中奇数的点。。。于是问题就变成判断C(n,m)奇偶性的问题了,有个结论C(n,m)是奇数当且仅当n&m==n。。。
// BEGIN CUT HERE // END CUT HERE
#line 5 "CheckerExpansion.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 CheckerExpansion
{
public:
vector <string> resultAfter(long long t, long long x0, long long y0, int w, int h){
//$CARETPOSITION$
vector<string> ret;
// t = 5;x0 = 0;y0 = 0;w = 10;h = 10;
for(int i = ;i < h;i++){
string tmp = "";
for(int j = ;j < w;j++){
char will;
long long x = x0 + j;
long long y = y0 + h - i - ;
// if(x == y)cout <<"x : " <<x<<" y:"<<y<<endl;
if((x + y) % == ){
if(x < y){
will = '.';
}else{
long long row = (x + y) / ;
long long column = abs(x - row);
if(row + > t){
will = '.';
}else if((row & column) == column){
if(row % == ){
will = 'A';
}else{
will = 'B';
}
}else{
will = '.';
}
}
}else{
will = '.';
}
// if(x == y)cout<<will<<endl;
tmp += will;
}
ret.push_back(tmp);
// cout << tmp << endl; }
return ret; } // 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(); }
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 vector <string> &Expected, const vector <string> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
void test_case_0() { long long Arg0 = 1LL; long long Arg1 = 0LL; long long Arg2 = 0LL; int Arg3 = ; int Arg4 = ; string Arr5[] = {"....", "....", "....", "A..." }; vector <string> Arg5(Arr5, Arr5 + (sizeof(Arr5) / sizeof(Arr5[]))); verify_case(, Arg5, resultAfter(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_1() { long long Arg0 = 5LL; long long Arg1 = 4LL; long long Arg2 = 1LL; int Arg3 = ; int Arg4 = ; string Arr5[] = {"A..", "...", "B..", ".B." }; vector <string> Arg5(Arr5, Arr5 + (sizeof(Arr5) / sizeof(Arr5[]))); verify_case(, Arg5, resultAfter(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_2() { long long Arg0 = 1024LL; long long Arg1 = 1525LL; long long Arg2 = 512LL; int Arg3 = ; int Arg4 = ; string Arr5[] = {"B...B...B...........", ".B.A.B.A.B.........." }; vector <string> Arg5(Arr5, Arr5 + (sizeof(Arr5) / sizeof(Arr5[]))); verify_case(, Arg5, resultAfter(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_3() { long long Arg0 = 53LL; long long Arg1 = 85LL; long long Arg2 = 6LL; int Arg3 = ; int Arg4 = ; string Arr5[] = {".....", ".....", "B....", ".B.A.", ".....", ".....", ".....", ".....", ".....", ".....", "B....", ".B...", "..B..", ".A.B." }; vector <string> Arg5(Arr5, Arr5 + (sizeof(Arr5) / sizeof(Arr5[]))); verify_case(, Arg5, resultAfter(Arg0, Arg1, Arg2, Arg3, Arg4)); } // END CUT HERE };
// BEGIN CUT HERE
int main(){
CheckerExpansion ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
500pt
topcoder srm 550的更多相关文章
- topcoder srm 550 div1
problem1 link 因为数据比较小,直接开一个二维数组记录哪些格子已经遍历,哪些还没有.进行模拟即可. problem2 link 模拟一些小数据,可以发现,AB的形状以及要求的区间是下面的样 ...
- 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 ...
随机推荐
- uva11925 Generating Permutations
逆序做,逆序输出 紫书上的描述有点问题 感觉很经典 ans.push_back(2); a.insert(a.begin(),a[n-1]); a.erase(a.end()-1); a.push_b ...
- Linux-RedHat7.2 安装.net core2.0
1.添加dotnet产品Feed sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'ech ...
- stay hungry stay foolish.
I am honored to be with you today at your commencement from one of the finest universities in the wo ...
- OpenCV2:第二章 创建图像并显示
一.简介 相当于在PS中,新建一个画布 二.CvMat类/LPLImage和CvMat结构体 参考: OpenCV2:第一章 图像表示 三.create() Mat m(2,2,CV_8UC3); m ...
- luogu P3916 图的遍历
P3916 图的遍历 题目描述 给出 N 个点, M 条边的有向图,对于每个点 v ,求 A(v) 表示从点 v 出发,能到达的编号最大的点. 输入输出格式 输入格式: 第1 行,2 个整数 N,MN ...
- c++的if语句中的110为什么不等于110?
从上图可以看出,当表达式1.1*x被直接放进if的判断括号中时1.1*x不等于y,但是将1.1*x赋值给z时,z与y相等,这是为什么?(以下为不等价时的代码) #include<stdio.h& ...
- sql语句执行顺序与性能优化(1)
一.首先我们看一下mysql的sql语句的书写顺序 . select--distinct--from--on--where--group by--having--聚合函数cube.rollup--or ...
- 常见的linux命令及其翻译
常见的linux指令 1.ls ll 查看文件信息 2.cd 切换工作目录 cd 或 cd ~ 切换到/home/用户目录 cd. 切换到当前目录 cd.. 切换到上级目录 cd- 切换入上次所在的目 ...
- ubuntu14.04 configure: error: xml2-config not found. Please check your libxml2 installation错误解决
今天在ubuntu14.04上安装php7时 执行:./configure命令时 一直报configure: error: xml2-config not found. Please check yo ...
- SolrCloud架构
原文链接 https://blog.csdn.net/dingzfang/article/details/42804489 1 核心概念 Collection Shard 均为逻辑上的概念 Core为 ...