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\),主 ...
随机推荐
- ACM计算几何模板——圆和球
#include <iostream> #include <cmath> using namespace std; #define eps 1e-10 /********** ...
- [转]谈谈Linux下动态库查找路径的问题
http://blog.chinaunix.net/uid-23069658-id-4028681.html 学习到了一个阶段之后,就需要不断的总结.沉淀.清零,然后才能继续“上路”.回想起自己当年刚 ...
- AWS系列-EC2默认限制说明
Amazon EC2 提供您可以使用的不同资源,例如实例和卷. 在您创建 AWS 账户时,AWS 会针对每个区域中的这些资源设置限制.此页面列出您在 亚太区域 (东京) 中的 EC2 服务限制. 1. ...
- 使用js里面的迭代器filter实现数组去重
实现数组去重的方法很多,最原始的方法是一个值一个值的去遍历,写到空数组里面: let r=[],arr = ['a', 'b', 'c', 'a']; for(var i=0,len=arr.leng ...
- java后台高德经纬度转地理位置信息
import java.util.LinkedList;import java.util.List; import org.apache.http.HttpResponse;import org.ap ...
- 【BZOJ1135】[POI2009]Lyz 线段树
[BZOJ1135][POI2009]Lyz Description 初始时滑冰俱乐部有1到n号的溜冰鞋各k双.已知x号脚的人可以穿x到x+d的溜冰鞋. 有m次操作,每次包含两个数ri,xi代表来了x ...
- 安卓EmojiTextView 和EmojiEditText
https://github.com/rockerhieu/emojicon 用法和TextView一样. 发送的时候用UTF-8 String enCodedStatusCode = "& ...
- POI导出EXCEL经典实现(转载)
1.Apache POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程式对Microsoft Office格式档案读和写的功能. .NET的开发人员则 ...
- axios post传参后台无法接收问题
起因是在angular项目中使用axios发送post请求,向后台传参后台一直无法接收,网上查了有说是请求头设置不对,需要把Content-Type:application/x-www-form-ur ...
- 2017-2018-2 20165330 实验三《敏捷开发与XP实现》实验报告
实验内容 P基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件开发:即将软件需求分析.软件设计.软件构建.软件测试和软件维护这些相关技术和过程统一到一个体系中 敏捷开发:是一种以人为核 ...