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\),主 ...
随机推荐
- RF中空列表变量不能直接赋至为[]
RF中空列表正确定义方法为:
- leetcode -- Balanced Binary Tree TODO
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- java基础---->Java中异常的使用(一)
今天我们大致学习一下java中关于异常的知识.原来忍住一段时间不联系一个人,真的就不想联系了. java异常的使用 一.java异常的一些说明 .Throwable 类是Java 语言中所有错误或异常 ...
- 安装PHP扩展-----phpredis
一.redis介绍 redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了 memcached的不足,它支持存储的value类型相 ...
- 【BZOJ4518】[Sdoi2016]征途 斜率优化
[BZOJ4518][Sdoi2016]征途 Description Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除 ...
- Spring + MyBatis中常用的数据库连接池配置总结
Spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源. DBCP数据源 DBCP类包位于 ...
- Vue基础-渲染函数-父子组件-传递数据
Vue 测试版本:Vue.js v2.5.13 做了个 demo,把父子组件的数据都绑定到 Vue 实例 app 上,注释中的 template 相对好理解些 <div id="app ...
- centos安装Oracle virtual box
1.进入virtualbox官网 https://www.virtualbox.org/wiki/Downloads 2.点击Linux distributions 3.向下翻至如图 4.在/etc/ ...
- SaltStack数据系统-Pillar
上一篇:SaltStack数据系统-Grains 使用saltstack进行配置管理可以使用pillar定义主机假如是Openstack修改了一下nova的密码就需要修改很多配置文件 pillar很安 ...
- Android logcat详细用法
admin| 2011-10-29 11:16| 分类:学习文档| Android logcat | 评论:[0]| Android日志系统提供了记录和查看系统调试信息的功能.日志都是从各种软件和 ...