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 ...
随机推荐
- nginx 的编译安装及基本操作
下载nginx [root@nginx ~]# wget http://nginx.org/download/nginx-1.14.0.tar.gz --2019-05-02 21:52:23-- h ...
- k8s 重要概念[转]
在实践之前,必须先学习 Kubernetes 的几个重要概念,它们是组成 Kubernetes 集群的基石. Cluster Cluster 是计算.存储和网络资源的集合,Kubernetes 利用这 ...
- nodeJS和npm的环境配置
1.windows下的NodeJS安装是比较方便的(v0.6.0版本之后,支持windows native),只需要登陆官网(http://nodejs.org/),便可以看到首页的“INSTALL” ...
- css内容补充之其它
1.overflow 当图片大小,超出div的大小时,可以指定overflow值为auto(带滚动条).hidden(隐藏,只显示一块): hover 当鼠标移动到当前标签上时,以下css属性才生效:
- htmlpurifier的使用
什么是htmlpurifier?? HTML Purifier是一个可以用来移除所有恶意代码(XSS),而且还能确保你的页面遵循W3C的标准规范的PHP类库. 在php里解决XSS最简单的方法是使用h ...
- Spring拓展接口之BeanPostProcessor,我们来看看它的底层实现
前言 开心一刻 小明:“妈,我被公司开除了”,妈:“啊,为什么呀?”, 小明:“我骂董事长是笨蛋,公司召开高层会议还要起诉我”,妈:“告你诽谤是吧?”,小明:“不是,他们说要告我泄露公司机密” Bea ...
- JSP配置即报错以及解决办法(未更新完)
JSP: JAVA Server Page 使用JAVA语言编写的一种在服务器运行的动态页面 JSP = JAVA + HTML JSP 的执行过程 1: 翻译阶段 把JSP源文件翻译成 java ...
- 跟初学者学习IbatisNet第二篇
在上一篇里面我们知道了什么是IbatisNet,并且知道了如何用IbatisNet进行简单的增删改查的操作,在这一篇文章里面我们主要介绍一下IbatisNet操作存储过程. 我们一般把存储过程分为两种 ...
- 大数据学习——hdfs客户端流式操作代码的实现
package cn.itcast.bigdata.hdfs.diceng; import org.apache.hadoop.conf.Configuration; import org.apach ...
- Python补充--Python内置函数清单
Python内置函数 Python内置(built-in)函数随着python解释器的运行而创建.在Python的程序中,你可以随时调用这些函数,不需要定义.最常见的内置函数是: print(&quo ...