DIV1 250pt

题意:以linux系统中文件系统的路径表示方法为背景,告诉你某文件的绝对路径和当前位置,求相对路径。具体看样例。

解法:模拟题,不多说。每次碰到STL的题自己的代码都会显得很sb...同时速度真的太不够了....

tag:模拟题

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "RelativePath.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 CLR(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<<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 maxint = ; VS p, c;
string temp = "../"; class RelativePath
{
public:
string makeRelative(string pat, string cur){
p.clear(); c.clear();
string s;
for (int i = ; i < pat.size(); ++ i){
s.clear();
while (i < (int)pat.size() && pat[i] != '/'){
s.PB (pat[i]); ++ i;
}
if (s.size()) p.PB (s);
}
for (int i = ; i < cur.size(); ++ i){
s.clear();
while (i < cur.size() && cur[i] != '/'){
s.PB (cur[i]); ++ i;
}
if (s.size()) c.PB (s);
} int t1 = , t2 = ;
while (t1 < p.size() && t2 < c.size()){
if (p[t1] == c[t2])
++ t1, ++ t2;
else break;
}
string ans; ans.clear();
for (int i = ; i < c.size()-t2; ++ i) ans += temp;
for (int i = t1; i < p.size(); ++ i){
if (i != t1) ans.PB ('/');
ans += p[i];
}
return ans;
} // 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 Arg0 = "/home/top/data/file"; string Arg1 = "/home/user/pictures"; string Arg2 = "../../top/data/file"; verify_case(, Arg2, makeRelative(Arg0, Arg1)); }
void test_case_1() { string Arg0 = "/home/user/movies/title"; string Arg1 = "/home/user/pictures"; string Arg2 = "../movies/title"; verify_case(, Arg2, makeRelative(Arg0, Arg1)); }
void test_case_2() { string Arg0 = "/file"; string Arg1 = "/"; string Arg2 = "file"; verify_case(, Arg2, makeRelative(Arg0, Arg1)); }
void test_case_3() { string Arg0 = "/a/b/a/b/a/b"; string Arg1 = "/a/b/a/a/b/a/b"; string Arg2 = "../../../../b/a/b"; verify_case(, Arg2, makeRelative(Arg0, Arg1)); }
void test_case_4() { string Arg0 = "/root/root/root"; string Arg1 = "/root"; string Arg2 = "root/root"; verify_case(, Arg2, makeRelative(Arg0, Arg1)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
RelativePath ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

DIV1 500pt

题意:对于一个边权均为1的强连通图,每两点之间有且仅有一条路。若能从任意点走x步之后回到该点,则称x为幸运数。用一个数列a[](0-based)表示是否是幸运数,如果i为幸运数a[i-1] = 1,否则a[i-1] = 0。可以证明,a[]一定会出现循环,找出最小的循环节和它最早出现的位置。比如“0011011111111”可以表示成"00110111(11)",也可以表示成 "00110(1)",但是要返回后者。n <= 30。

解法:首先,给出两个结论:1、若x为幸运数,则x一定是a[]的循环节之一;2、若x,y均为a[]的循环节,则gcd(x, y)也为a[]的循环节;3、若x,y均为循环节,则第一个循环节出现的位置不会在x*y之后。

   那么,这道题的数据范围就被限制出来了。循环节最长为30,返回的答案长度最长为900 + 30 + 2。所以,直接暴力2000以内所有的数是否是幸运数,然后再暴力枚举循环节长度和循环起始位置即可。。。。。。

tag:think, good

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "AllCycleLengths.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 map<int, int> mpii;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ;
const int N = ; int n;
int con[], tcon[]; class AllCycleLengths
{
public:
string findAll(vector <string> arc){
n = sz(arc);
clr0 (con);
set<int> st;
VI a, b;
for (int i = ; i < n; ++ i){
b.clear(); a.clear(); a.pb (i);
int times = ;
while (times <= N){
++ times;
set<int> st;
for (int j = ; j < sz(a); ++ j)
for (int k = ; k < n; ++ k)
if (arc[a[j]][k] == 'Y' && !st.count(k)){
b.pb (k); st.insert(k);
}
for (int j = ; j < sz(b); ++ j)
if (b[j] == i) con[times] = ;
a = b; b.clear();
}
} for (int rec = ; rec < ; ++ rec){
int pos = -, end = -;
for (int i = ; i <= N / ; ++ i){
int ok = , flag = i + rec, times = ;
while (times < && flag + rec < N){
ok = ;
for (int t = ; t < rec; ++ t)
if (con[i+t] != con[flag+t]){
ok = ; break;
}
if (!ok) break;
++ times; flag += rec;
}
if (ok){
pos = i; end = pos + rec - ;
break;
}
}
if (pos == -) continue;
out (pos); string ret; ret.clear();
for (int i = ; i <= end; ++ i){
if (i == pos) ret.pb ('(');
ret.pb (con[i] + '');
}
ret.pb (')');
return ret;
}
return "(0)";
} // 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(); }
//void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0();}
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[] = {"NNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNY", "NNYNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNYNNNNNNNNN", "YNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNYNNNNNNNNNNNNNNNN", "NNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYNNNN", "NNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYNNNNNNNN", "NYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYNNNNNN"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arg1 = "0010010110110(1)"; verify_case(, Arg1, findAll(Arg0)); }
//void test_case_0() { string Arr0[] = {"NYNN", "NNYY", "NNNY", "YNNN"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arg1 = "00110(1)"; verify_case(0, Arg1, findAll(Arg0)); }
void test_case_1() { string Arr0[] = {"NY", "YN"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arg1 = "(01)"; verify_case(, Arg1, findAll(Arg0)); }
void test_case_2() { string Arr0[] = {"NYYYY", "NNYYY", "NNNYY", "NNNNY", "YNNNN"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arg1 = "0(1)"; verify_case(, Arg1, findAll(Arg0)); }
void test_case_3() { string Arr0[] = {"NYNNN", "NNYNN", "NNNYN", "NNNNY", "YNNYN"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); string Arg1 = "010(1)"; verify_case(, Arg1, findAll(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
//freopen( "a.out" , "w" , stdout );
AllCycleLengths ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 405(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. Bootstrap Table的例子(转载)

    转载自:http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html#classes-table 使用的API: data1.json da ...

  2. How to Make LastPass Even More Secure with Google Authenticator

    Google Authenticator LastPass supports Google Authenticator, which is officially available as an app ...

  3. 添加Pods后,import无提示的解决办法

    选择工程的 Target -> Build Settings 菜单,找到\”User Header Search Paths\”设置项 新增一个值"$(PODS_ROOT)" ...

  4. Objective-C消息机制的原理

    http://desheng.me/2012/03/31/objective-c%E6%B6%88%E6%81%AF%E6%9C%BA%E5%88%B6%E7%9A%84%E5%8E%9F%E7%90 ...

  5. JavaScript Boolean(布尔) 对象

    创建 Boolean 对象 Boolean 对象代表两个值:"true" 或者 "false" 下面的代码定义了一个名为 myBoolean 的布尔对象: va ...

  6. Git 基础再学习之:git checkout -- file

    首先明白一下基本概念和用法,这段话是从前在看廖雪峰的git教程的时候摘到OneNote的 准备工作: 新建了一个learngit文件夹,在bash中cd进入文件夹,用以下命令创建一个仓库. $ git ...

  7. Mac OS X 系统下快速显示隐藏文件的方法(使用Automator创建workflow)

    有的时候需要显系统中的隐藏文件,在 Mac 中不像windows系统那么方便(勾选选项就能够操作),需要在 Terminal 中执行: localhost:~ mx$ defaults write c ...

  8. centos6.2下搭建Web服务器

    1.安装Apache2 yum install httpd 2.启动 方法一:service httpd start 方法二:/etc/init.d/httpd start //浏览http://ip ...

  9. 谨慎使用php的strtotime()函数

    我们在日常业务中,针对业务量,经常会采用对数据库按时间做横向分表,分表后的查询往往会涉及到时间问题.例如,我们想查询某个用户距离当前时间1个月的订单情况,在这个时候,我们有些会用到strtotime( ...

  10. python内置字符串操作方法

    1.capitalize() S.capitalize()->string 首字母大写,其余字母小写. str='A222aaA' str.capitalize()#首字母大写,其余字母小写. ...