嗯。。。。今天的500确实比较好

DIV1 250

  模拟。。。略

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "CubeWalking.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ;
int temp[][] = {{, -}, {, }, {, }, {-, }}; class CubeWalking
{
public:
string finalPosition(string mov){
int n = sz(mov);
int x = , y = , dic = ;
for (int i = ; i < n; ++ i){
if (mov[i] == 'L') dic = (dic + ) % ;
else if (mov[i] == 'R') dic = (dic + ) % ;
if (mov[i] == 'W') x = (x + temp[dic][] + ) % , y = (y + temp[dic][] + ) % ;
}
if (x == && y == ) return "GREEN";
if (!x && y == ) return "BLUE";
if (!y && x == ) return "BLUE";
if (y == && x == ) return "BLUE";
if (x == && y == ) return "BLUE";
return "RED";
} // 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 string &Expected, const string &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 Arg0 = "LLRR"; string Arg1 = "GREEN"; verify_case(, Arg1, finalPosition(Arg0)); }
void test_case_1() { string Arg0 = "WWWWWWWWWWWW"; string Arg1 = "GREEN"; verify_case(, Arg1, finalPosition(Arg0)); }
void test_case_2() { string Arg0 = "WLWRW"; string Arg1 = "RED"; verify_case(, Arg1, finalPosition(Arg0)); }
void test_case_3() { string Arg0 = "WWLLWRWLWLLRWW"; string Arg1 = "BLUE"; verify_case(, Arg1, finalPosition(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
CubeWalking ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

DIV1 500

题意:给定一个有n个点的带权图,有一个蚂蚁要从点0到点1,它每秒走stp步,最多能走tim秒,走的时间可以少于tim秒,但一定要是整数秒。问,若蚂蚁得分为它通过的边权之和(通过某边两次则得两次分),则求最大得分,若不能用整数秒走到1并停下,输出IMPOSSIBLE。

   n <= 50, stp <= 100, tim <= 10^9。

解法:首先,如果要求一定要走tim,那就很简单了,用矩阵乘法快速幂可以解决。

   至于走的时间可以少于tim,处理方法就是加一条1到1,长度为1s,边权为0的自环。

   然后,首先用矩阵乘法快速幂算出用时1s,从i点走到j点得分最高为多少。再赋值A[1][1] = max(A[1][1], 0)(若A[1][1]大于0则不用赋值),然后再调用矩阵乘法快速幂即可。

tag:graph, matrix, 快速幂, good

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "AntOnGraph.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef long long int64;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef int64 mtx[][]; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ;
const int64 temp = - (1LL<<); class AntOnGraph
{
public:
int dit[], n;
void mtx_eql(mtx &a, mtx b)
{
for (int i = ; i < n; ++ i) for (int j = ; j < n; ++ j) a[i][j] = b[i][j];
}
void mtx_mul(mtx &a, mtx b)
{
mtx ret;
for (int i = ; i < n; ++ i)
for (int j = ; j < n; ++ j){
ret[i][j] = temp;
for (int k = ; k < n; ++ k)
if (a[i][k] != temp && b[k][j] != temp)
ret[i][j] = max(ret[i][j], a[i][k] + b[k][j]);
} mtx_eql(a, ret);
}
void mtx_pow(mtx &an, int64 num)
{
if (num == ) return; mtx ret; mtx_eql(ret, an);
-- num; while (num){
if (num & ) mtx_mul(ret, an);
num >>= ;
mtx_mul(an, an);
} mtx_eql(an, ret);
} string gao(int64 x)
{
int len = ;
bool u = ;
if (x < ) x = - x, u = ; while (x){
dit[len++] = x % ;
x /= ;
} if (!len) return "";
string ret; ret.clear();
if (u) ret.pb ('-');
for (int i = len-; i >= ; -- i) ret.pb (dit[i] + '');
return ret;
}
string maximumBonus(vector <string> p0, vector <string> p1, vector <string> p2, int stp, int tim){
n = sz(p1);
int cnt = ;
mtx an;
for (int i = ; i < n; ++ i)
for (int j = ; j < n; ++ j){
cnt = * (p0[i][j]-'') + * (p1[i][j] - '') + p2[i][j] - '';
if (cnt == ) an[i][j] = temp;
else an[i][j] = cnt - ;
} mtx_pow(an, (int64)stp);
if (an[][] < ) an[][] = ; mtx_pow(an, (int64)tim);
if (an[][] == temp) return "IMPOSSIBLE";
else return gao(an[][]);
} // 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(); }
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 string &Expected, const string &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[]))); string Arr1[] = {"",""}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); string Arr2[] = {"",""}; vector <string> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; int Arg4 = ; string Arg5 = ""; verify_case(, Arg5, maximumBonus(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_1() { string Arr0[] = {"",""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arr1[] = {"",""}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); string Arr2[] = {"",""}; vector <string> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; int Arg4 = ; string Arg5 = "IMPOSSIBLE"; verify_case(, Arg5, maximumBonus(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_2() { string Arr0[] = {"","","",""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arr1[] = {"","","",""}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); string Arr2[] = {"","","",""}; vector <string> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; int Arg4 = ; string Arg5 = ""; verify_case(, Arg5, maximumBonus(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_3() { string Arr0[] = {"","","",""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arr1[] = {"","","",""}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); string Arr2[] = {"","","",""}; vector <string> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; int Arg4 = ; string Arg5 = "-5"; verify_case(, Arg5, maximumBonus(Arg0, Arg1, Arg2, Arg3, Arg4)); }
void test_case_4() { string Arr0[] = {"","","",
"","","",
"","","",
"","",""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arr1[] = {"","","",
"","","",
"","","",
"","",""}; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); string Arr2[] = {"","","",
"","","",
"","","",
"","",""}; vector <string> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[]))); int Arg3 = ; int Arg4 = ; string Arg5 = ""; verify_case(, Arg5, maximumBonus(Arg0, Arg1, Arg2, Arg3, Arg4)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
AntOnGraph ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 446(1-250pt, 1-500pt)的更多相关文章

  1. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  2. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  3. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  4. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  5. topcoder srm 553

    div1 250pt: 题意:... 解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下. // BEGIN ...

  6. topcoder srm 552

    div1 250pt: 题意:用RGB三种颜色的球摆N层的三角形,要求相邻的不同色,给出RGB的数量,问最多能摆几个 解法:三种颜色的数量要么是全一样,要么是两个一样,另外一个比他们多一个,于是可以分 ...

  7. topcoder srm 551

    div1 250pt 题意:一个长度最多50的字符串,每次操作可以交换相邻的两个字符,问,经过最多MaxSwaps次交换之后,最多能让多少个相同的字符连起来 解法:对于每种字符,枚举一个“集结点”,让 ...

  8. topcoder srm 550

    div1 250pt: 题意:有个机器人,从某一点出发,他只有碰到地形边缘或者碰到走过的点时才会改变运动方向,然后接着走,现在给出他的运动轨迹,判断他的运动是否合法,如果合法的话,那么整个地形的最小面 ...

  9. topcoder srm 610

    div1 250pt: 题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵. 解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新 ...

随机推荐

  1. Java LoggingAPI 使用方法

    因为不想导入Log4j的jar,项目只是测试一些东西,因此选用了JDK 自带的Logging,这对于一些小的项目或者自己测试一些东西是比较好的选择. Log4j中是通过log4j.properties ...

  2. mybatis()

    ---------------------------------mysql分页---------------------------------- public void selectList(in ...

  3. dom 笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Python内存管理及引用计数

    作为一门动态语言,python很重要的一个概念就是动态类型,即对象的类型和内存占用都是运行时确定的.(Why?)运行时,解释器会根据语法和右操作数来决定新对象的类型.动态类型的实现,是通过引用和对象的 ...

  5. /etc/rc.local ; /etc/init.d ;/etc/profile;/etc/bashrc;~/.bash_profile;~/.bashrc;~/.bash_logout

    1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里. 把脚本程序写在/etc/rc.d/init.d/目录下也可以  在完成 run level 3 ...

  6. [转载]5分钟了解Mockito

    原文链接: http://liuzhijun.iteye.com/blog/1512780/ 5分钟了解Mockito 博客分类: Open SourceJava 一.什么是mock测试,什么是moc ...

  7. Struts, Namespace用法

    最近在用SSH框架做一个项目,在使用Struts 的namespace时遇到不少问题,现在就对struts namespace 做一个简单的介绍吧.(本文从项目结构展开叙述) (第1次写博客, 写的不 ...

  8. Word图片显示不完整

    选中图片和上下文字,段落里选择单倍行距,其他行距不行.

  9. Spring 配置方式

    1.bean的配置方式:通过全类名(反射),通过工厂方法(静态工厂方法&实例工厂方法).FactoryBean. 2.静态工厂方法:直接调用某一个类的静态方法就可以返回bean的实例. cla ...

  10. Analysis Guidelines

    This section describes some best practices for analysis. These practices come from experience of ana ...