topcoder SRM712 Div1 LR
题目:
Problem Statement |
|||||||||||||
We have a cyclic array A of length n. For each valid i, element i-1 the left neighbor of element i. Additionally, element n-1 is the left neighbor of element 0.
You are given two vector<long long>s s and t, each with n elements. Currently, we have A[i] = s[i] for each valid i. Our goal is to have A[i] = t[i] for each valid i. We can use two operations that modify the contents of A:
Note that all changes happen simultaneously. For example, if you use the operation L, the new value of A[7] is computed as the sum of the old value of A[7] and the old value of A[6]. If there is no way to reach the desired goal state, return "No solution". Otherwise return any valid way of doing so by using at most 100 operations. More precisely, return one valid sequence of operations encoded as a string of 'L's and 'R's. If there are multiple valid solutions, you may return any of them. In particular, you are not required to find the shortest valid solution. Any valid solution will be accepted as long as its length does not exceed 100. We can prove that if there is an valid solution then there must exist one with length at most 100. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- | s will contain between 2 and 50 elements, inclusive. | ||||||||||||
- | s and t will contain the same number of elements. | ||||||||||||
- | Each element in s will be between 0 and 1,000,000,000,000,000 (10^15) inclusive. | ||||||||||||
- | Each element in t will be between 0 and 1,000,000,000,000,000 (10^15) inclusive. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
|||||||||||||
4) | |||||||||||||
|
|||||||||||||
5) | |||||||||||||
|
|||||||||||||
6) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
思路:因为这是一个圆形数列,所以L和R所得的数列是差不多的,只是左移右移一次的区别。
所以先判断进行sum次操作(通过数列值的和判断)。
然后先进行sum次L操作,再判断把进行sum次操作后的数列k次右平移后能否得到t数列。
能到得到的话则是进行了k次R,sum-k次L操作,LR的先后顺序没有关系。
// BEGIN CUT HERE #include <conio.h>
#include <sstream>
/*
*/
#define debuging
#ifdef debuging
#define FIN {freopen("new.in" , "r" , stdin) ;}
#define FOUT {freopen("new.out" , "w" , stdout) ;}
#define OUT(x) {cout<< #x << " : " << x <<endl ;}
#define ERR(x) {cout<<"#error: "<< x ; while(1) ;}
#endif
// END CUT HERE
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; class LR
{
public:
string construct(vector<long long> s, vector<long long> t)
{
int cnt=;
LL suma=,sumb=,sum=;
string ans;
for(int i=; i<s.size(); i++)
suma+=s[i],sumb+=t[i];
if(suma==sumb) sum=;
for(int i=; i<=&∑ i++)
if((suma*=) == sumb)
{
sum=i;
break;
}
if(suma!=sumb)
return "No solution";
for(LL i=,n=s.size(); i<sum; i++)
for(LL j=,ls=s[n-],tmp; j<n; j++)
tmp=s[j],s[j]+=ls,ls=tmp;
for(int i=; i<=sum; i++)
{
if(s==t)
{
cnt=i;break;
}
s.insert(s.begin(),s[s.size()-]);
s.erase(--s.end());
}
if(cnt>sum)
return "No solution";
if(sum==)
return "";
for(int i=; i<cnt; i++)
ans+="R";
for(int i=cnt; i<sum; i++)
ans+="L";
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();
if ((Case == -) || (Case == )) test_case_5();
if ((Case == -) || (Case == )) test_case_6();
}
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()
{
LL Arr0[] = {,,,,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,,,,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "LL";
verify_case(, Arg2, construct(Arg0, Arg1));
}
void test_case_1()
{
LL Arr0[] = {,,,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,,,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "No solution";
verify_case(, Arg2, construct(Arg0, Arg1));
}
void test_case_2()
{
LL Arr0[] = {,,,,,,,,,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,,,,,,,,,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "No solution";
verify_case(, Arg2, construct(Arg0, Arg1));
}
void test_case_3()
{
LL Arr0[] = {,,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "RRRRR";
verify_case(, Arg2, construct(Arg0, Arg1));
}
void test_case_4()
{
LL Arr0[] = {,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "RLLLRRRLLRRRLRLRRLLLLRLLRRLRRRLRRLRRLLRRRLLRRRLLL";
verify_case(, Arg2, construct(Arg0, Arg1));
}
void test_case_5()
{
LL Arr0[] = {,,,,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,,,,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "No solution";
verify_case(, Arg2, construct(Arg0, Arg1));
}
void test_case_6()
{
LL Arr0[] = {,};
vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[])));
LL Arr1[] = {,};
vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[])));
string Arg2 = "";
verify_case(, Arg2, construct(Arg0, Arg1));
} // END CUT HERE };
// BEGIN CUT HERE
int main()
{
LR ___test;
___test.run_test();
getch() ;
return ;
}
// END CUT HERE
topcoder SRM712 Div1 LR的更多相关文章
- TopCoder 649 div1 & div2
最近一场TC,做得是在是烂,不过最后challenge阶段用一个随机数据cha了一个明显错误的代码,最后免于暴跌rating,还涨了一点.TC题目质量还是很高的,非常锻炼思维,拓展做题的视野,老老实实 ...
- TopCoder SRM500 Div1 250 其他
原文链接https://www.cnblogs.com/zhouzhendong/p/SRM500-250.html SRM500 Div1 250 题意 (看题用了半个小时--) 有 n 个人(编号 ...
- TopCoder SRM500 Div1 500 分治
原文链接https://www.cnblogs.com/zhouzhendong/p/SRM500-500.html SRM500 Div1 500 没想到 double 的精度居然没有爆-- 考虑以 ...
- TopCoder SRM500 Div1 1000 其他
原文链接https://www.cnblogs.com/zhouzhendong/p/SRM500-1000.html SRM500 Div1 1000 设 \(v_1,v_2,\cdots ,v_9 ...
- TopCoder SRM502 Div1 500 贪心 01背包
原文链接https://www.cnblogs.com/zhouzhendong/p/SRM502-500.html SRM502 Div1 500 好题. 首先,如果已经确定了解决所有问题的优先级, ...
- TopCoder SRM502 Div1 1000 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/SRM502-1000.html SRM502 Div1 1000 题意 从 [0,n-1] 中选择 k 个不同的 ...
- TopCoder 603 div1 & div2
div2 250pts MiddleCode 题意:s串长度为奇数时,将中间字符取掉并添加到t末尾:长度为偶数时,将中间两个较小的字符取掉并添加到末尾. 分析:直接做,学习了一下substr(s, p ...
- TopCoder SRM704 Div1 800 构造
原文链接https://www.cnblogs.com/zhouzhendong/p/SRM704-800.html 题解 考虑构造一个 $n = 20$ 的图. 先把所有 $i$ 都连向 $i-1$ ...
- topcoder SRM642 div1 hard WheelofFortune
题目链接:vjudge 大意:有两个人参加一场游戏,这个游戏在一个编号为\(0\text~n-1\)的轮盘上进行,一开始轮盘上的数字均为0:一共有\(m\)轮,每一轮都有一个操作参数\(s_i\),主 ...
随机推荐
- spring配置文件头部配置解析
http://blog.csdn.net/f_639584391/article/details/50167321
- Asp.net中的Cache--HttpRuntim.Cache 和 HttpContext.Current.Cache
在ASP.NET中有两个类都提供缓存支持, 一个是HttpRuntime类的Cache属性, 另一个是HttpContext类的Cache属性. 通过查看这两个属性的类型可以发现其实这两个属性都是Sy ...
- JavaScript作用域原理——作用域根据函数划分
一.一个for实例 <p id="scope3" style="color:red"></p> var pscope3 = docume ...
- 非IE图片上传预览
$("#uploadFiles").change(function (e) { if (e.target.files) { ...
- 【BZOJ5074】[Lydsy十月月赛]小B的数字 数学
[BZOJ5074][Lydsy十月月赛]小B的数字 题解:题目是问你ai*bi>=sum,bi>=0这个不等式组有没有解.因为a<=10,容易想到取ai的lcm,然后变成lcm*b ...
- LeetCode 笔记系列十 Suduko
题目:Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by ...
- a 标签 download 和 target 不配合
发现一个奇怪的事,看代码 <a id="downloadAlink" target="_blank" href="http://www.baid ...
- CH5202 自然数拆分Lunatic版【完全背包】
5202 自然数拆分Lunatic版 0x50「动态规划」例题 描述 给定一个自然数N,要求把N拆分成若干个正整数相加的形式,参与加法运算的数可以重复.求拆分的方案数 mod 2147483648的结 ...
- Exchange Pause or stop transport service
The Microsoft Exchange Transport service is a service available both on the Microsoft Exchange Serve ...
- ios开发 更改状态栏
设置statusBar 简单来说,就是设置显示电池电量.时间.网络部分标示的颜色, 这里只能设置两种颜色: 默认的黑色(UIStatusBarStyleDefault) 白色(UIStatusBarS ...