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 ...
随机推荐
- Python旅途——函数(1)
函数 简介 到目前为止,我们一直所接触的都是属于面向过程编程,这样的代码会降低代码的可读性,因此引入了函数式编程,在后面我们还会学到面向对象编程. 函数式编程 函数本质:将N行代码拿到别处,并给他起个 ...
- 数据结构( Pyhon 语言描述 ) — — 第4章:数据和链表结构
数据结构是表示一个集合中包含的数据的一个对象 数组数据结构 数组是一个数据结构 支持按照位置对某一项的随机访问,且这种访问的时间是常数 在创建数组时,给定了用于存储数据的位置的一个数目,并且数组的长度 ...
- LeetCode(100) Same Tree
题目 Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...
- Java多线程入门Ⅱ
线程的让步 线程让出自己占用的CPU资源 线程让出资源,不指定让给谁 线程让出资源,指定让给谁 方法1: public static void yield(); 线程实现交替打印 import jav ...
- 【HDU 1402】A * B Problem Plus(FFT)
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to e ...
- POJ 2976 Dropping test(01分数规划模板)
01分数划分详情可阅读:http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html 题意: 给出n个a和b,让选出n-k个使得最大 二 ...
- NOI模拟赛(3.15) sequence(序列)
Description 小A有N个正整数,紧接着,他打算依次在黑板上写下这N个数.对于每一个数,他可以决定将这个数写在当前数列的最左边或最右边.现在他想知道,他写下的数列的可能的最长严格上升子序列(可 ...
- SpringCloud源码地址
SpringCloud实战源代码 https://github.com/springcloud/spring-cloud-code.git
- 【Codeforces 1107D】Compression
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 先把所给的压缩形式的字符串转成二进制 然后对获得的01数组做一个前缀和(a[i][j]=以(i,j)为右下角,(1,1)为左上角的矩形内的数字 ...
- BeautifulSoup4系列一
前言 以博客园为例,爬取我的博客上首页的发布时间.标题.摘要,本篇先小试牛刀,先了解下它的强大之处,后面讲beautifulsoup4的详细功能. 一.安装 1.打开cmd用pip在线安装beauti ...