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. hdoj 1087 (DP)

    代码: #include<iostream>   #include<cmath>   using namespace std;  int a[1005], dp[1005];  ...

  2. this point

    // this.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> using namespa ...

  3. 数组Api .map()的使用

    之前并没有过多的使用过这个Api,在此记录下对其的理解,方便以后多多使用. 首先是对map的说明: var mappedArray = array.map(callback[, thisObject] ...

  4. YII Query Builder

    今天遇到一个Query Builder 联合查询问题: 查询关联表某个字段的总数

  5. C# 窗体间传值方法大汇总(转)

    第一种方法:创建一个类,里面声明用于存储接收的字段.传的时候存储于字段中,要用的时候,直接类名.字段名 进行调用.(这种方法传递是双向的) 第二种方法:1.在Form1里定义 public strin ...

  6. css+js自动化开发之第十五天

    一.css上一篇的补充 1.position(页面分层) (1)fiexd将标签固定在页面的某个位置 position属性:top,left,right,bottom (2)relative+abso ...

  7. python之加密

    import hashlib obj = hashlib.md5(bytes('adfasfasdfsfasf',encoding = 'utf-8')) obj.update(bytes('123' ...

  8. 再次探究Android ListView缓存机制

    概述 虽然现在5.0后Google推出了RecycleView,但在5.0 Lollipop普及前Listview仍会被广泛使用,所以打算再次探究一下Listview的源码,了解一下Listview ...

  9. 【C语言】结构组成(函数、语句、注释)

    C语言结构组成 一.相关基础知识 二.具体内容 C语言由函数.语句和注释三部分组成: )函数与主函数:     一个C语言源程序可以由一个或多个源文件组成,每个源文件可由一个或多个函数组成,一个源程序 ...

  10. JSP的优势与劣势浅析

    本文简单介绍了JSP技术,并对JSP的优势与劣势进行了简单的分析.JSP页面由HTML代码和嵌入其中的Java代码所组成. JSP(JavaServer Pages)是由Sun Microsystem ...