日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

topcoder SRM712 Div1 LR

發布時間:2023/12/10 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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:
  • Operation L: Each element is increased by the value of its left neighbor.
  • Operation R: Each element is increased by the value of its right neighbor.
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

????
Class:LR
Method:construct
Parameters:vector<long long>, vector<long long>
Returns:string
Method signature:string construct(vector<long long> s, vector<long long> t)
(be sure your method is public)

Limits

????
Time limit (s):2.000
Memory limit (MB):256
Stack limit (MB):256

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)?
????
{0,1,0,0,0}
{0,1,2,1,0}
Returns: "LL"
The first operation L will change A into {0,1,1,0,0} and then the second operation L will produce the array we wanted.
1)?
????
{0,0,0,1}
{0,1,0,0}
Returns: "No solution"
Even though A is cyclic, the precise indices matter. Here,?s?and?t?are two different configurations, and there is no valid way to change this?s?into this?t.
2)?
????
{1,2,3,4,5,6,7,8,9,10}
{12,24,56,95,12,78,0,100,54,88}
Returns: "No solution"
Regardless of the type and order of operations all elements of A will always remain positive. However,?t?contains a zero. Therefore,?t?cannot be reached.
3)?
????
{1,0,0}
{11,11,10}
Returns: "RRRRR"
The sequence of five operations R will change the array A as follows: {1,0,0} -> {1,0,1} -> {1,1,2} -> {2,3,3} -> {5,6,5} -> {11,11,10}.
4)?
????
{1,1}
{562949953421312,562949953421312}
Returns: "RLLLRRRLLRRRLRLRRLLLLRLLRRLRRRLRRLRRLLRRRLLRRRLLL"
We start with A[0] = A[1] = 1, and we want A[0] = A[1] = 2^49. We can easily verify that in this case each operation changes A from {x, x} into {2x, 2x}. Therefore, any string of exactly 49 'L's and 'R's is a valid answer.
5)?
????
{0,0,0,0,0}
{0,0,0,1,0}
Returns: "No solution"
?
6)?
????
{123,456}
{123,456}
Returns: ""
?

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的先后順序沒有關系。

1 // BEGIN CUT HERE 2 3 #include <conio.h> 4 #include <sstream> 5 /* 6 */ 7 #define debuging 8 #ifdef debuging 9 #define FIN {freopen("new.in" , "r" , stdin) ;} 10 #define FOUT {freopen("new.out" , "w" , stdout) ;} 11 #define OUT(x) {cout<< #x << " : " << x <<endl ;} 12 #define ERR(x) {cout<<"#error: "<< x ; while(1) ;} 13 #endif 14 // END CUT HERE 15 #include <bits/stdc++.h> 16 17 using namespace std; 18 19 #define MP make_pair 20 #define PB push_back 21 typedef long long LL; 22 typedef pair<int,int> PII; 23 const double eps=1e-8; 24 const double pi=acos(-1.0); 25 const int K=1e6+7; 26 const int mod=1e9+7; 27 28 29 class LR 30 { 31 public: 32 string construct(vector<long long> s, vector<long long> t) 33 { 34 int cnt=101; 35 LL suma=0,sumb=0,sum=1; 36 string ans; 37 for(int i=0; i<s.size(); i++) 38 suma+=s[i],sumb+=t[i]; 39 if(suma==sumb) sum=0; 40 for(int i=1; i<=100&&sum; i++) 41 if((suma*=2) == sumb) 42 { 43 sum=i; 44 break; 45 } 46 if(suma!=sumb) 47 return "No solution"; 48 for(LL i=0,n=s.size(); i<sum; i++) 49 for(LL j=0,ls=s[n-1],tmp; j<n; j++) 50 tmp=s[j],s[j]+=ls,ls=tmp; 51 for(int i=0; i<=sum; i++) 52 { 53 if(s==t) 54 { 55 cnt=i;break; 56 } 57 s.insert(s.begin(),s[s.size()-1]); 58 s.erase(--s.end()); 59 } 60 if(cnt>sum) 61 return "No solution"; 62 if(sum==0) 63 return ""; 64 for(int i=0; i<cnt; i++) 65 ans+="R"; 66 for(int i=cnt; i<sum; i++) 67 ans+="L"; 68 return ans; 69 } 70 71 72 // BEGIN CUT HERE 73 public: 74 void run_test(int Case) 75 { 76 if ((Case == -1) || (Case == 0)) test_case_0(); 77 if ((Case == -1) || (Case == 1)) test_case_1(); 78 if ((Case == -1) || (Case == 2)) test_case_2(); 79 if ((Case == -1) || (Case == 3)) test_case_3(); 80 if ((Case == -1) || (Case == 4)) test_case_4(); 81 if ((Case == -1) || (Case == 5)) test_case_5(); 82 if ((Case == -1) || (Case == 6)) test_case_6(); 83 } 84 private: 85 template <typename T> string print_array(const vector<T> &V) 86 { 87 ostringstream os; 88 os << "{ "; 89 for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; 90 os << " }"; 91 return os.str(); 92 } 93 void verify_case(int Case, const string &Expected, const string &Received) 94 { 95 cerr << "Test Case #" << Case << "..."; 96 if (Expected == Received) cerr << "PASSED" << endl; 97 else 98 { 99 cerr << "FAILED" << endl; 100 cerr << "\tExpected: \"" << Expected << '\"' << endl; 101 cerr << "\tReceived: \"" << Received << '\"' << endl; 102 } 103 } 104 void test_case_0() 105 { 106 LL Arr0[] = {0,1,0,0,0}; 107 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 108 LL Arr1[] = {0,1,2,1,0}; 109 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 110 string Arg2 = "LL"; 111 verify_case(0, Arg2, construct(Arg0, Arg1)); 112 } 113 void test_case_1() 114 { 115 LL Arr0[] = {0,0,0,1}; 116 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 117 LL Arr1[] = {0,1,0,0}; 118 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 119 string Arg2 = "No solution"; 120 verify_case(1, Arg2, construct(Arg0, Arg1)); 121 } 122 void test_case_2() 123 { 124 LL Arr0[] = {1,2,3,4,5,6,7,8,9,10}; 125 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 126 LL Arr1[] = {12,24,56,95,12,78,0,100,54,88}; 127 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 128 string Arg2 = "No solution"; 129 verify_case(2, Arg2, construct(Arg0, Arg1)); 130 } 131 void test_case_3() 132 { 133 LL Arr0[] = {1,0,0}; 134 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 135 LL Arr1[] = {11,11,10}; 136 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 137 string Arg2 = "RRRRR"; 138 verify_case(3, Arg2, construct(Arg0, Arg1)); 139 } 140 void test_case_4() 141 { 142 LL Arr0[] = {1,1}; 143 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 144 LL Arr1[] = {562949953421312,562949953421312}; 145 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 146 string Arg2 = "RLLLRRRLLRRRLRLRRLLLLRLLRRLRRRLRRLRRLLRRRLLRRRLLL"; 147 verify_case(4, Arg2, construct(Arg0, Arg1)); 148 } 149 void test_case_5() 150 { 151 LL Arr0[] = {0,0,0,0,0}; 152 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 153 LL Arr1[] = {0,0,0,1,0}; 154 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 155 string Arg2 = "No solution"; 156 verify_case(5, Arg2, construct(Arg0, Arg1)); 157 } 158 void test_case_6() 159 { 160 LL Arr0[] = {123,456}; 161 vector<long long> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); 162 LL Arr1[] = {123,456}; 163 vector<long long> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); 164 string Arg2 = ""; 165 verify_case(6, Arg2, construct(Arg0, Arg1)); 166 } 167 168 // END CUT HERE 169 170 }; 171 // BEGIN CUT HERE 172 int main() 173 { 174 LR ___test; 175 ___test.run_test(3); 176 getch() ; 177 return 0; 178 } 179 // END CUT HERE

?

轉載于:https://www.cnblogs.com/weeping/p/6739263.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的topcoder SRM712 Div1 LR的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 在线中文字幕视频 | 国产小视频网址 | 国产jzjzjz丝袜老师水多 | 秋霞成人网| 国产精品毛片一区 | 前任攻略在线观看免费完整版 | 精品视频在线一区 | 公交顶臀绿裙妇女配视频 | 美女裸体跪姿扒开屁股无内裤 | 黄色一区二区三区 | 人妻丰满熟妇av无码久久洗澡 | 青草视频在线观看视频 | 久久久久久久久国产 | 爱情岛论坛永久入址在线 | 秋霞成人午夜伦在线观看 | 亚洲福利视频一区二区三区 | 日本欧美三级 | 日韩精品一区二区在线播放 | 毛茸茸毛片 | 成人精品在线播放 | 久久久久久久久久一区二区三区 | 成人免费xxxxxx视频 | 国产精品178页 | 日韩中文字幕 | 国产一区二区三区四区三区四 | 久久色播| 99久久久国产精品 | 五月天激情婷婷 | av免费观看网址 | 精品一卡二卡三卡 | 无码人妻丰满熟妇区毛片18 | 亚洲性猛交xxxx乱大交 | 97在线免费视频 | 黄色网址www | 久久久久久亚洲中文字幕无码 | 91久久精品一区二区 | 亚洲精品国产精品国自产 | 国产精品理论片 | 日韩欧美一级视频 | 国产日产欧洲无码视频 | 成人激情综合 | 亚洲精品系列 | 一区二区三区波多野结衣 | 成年人网站在线 | 女性喷水视频 | 国产精品国产馆在线真实露脸 | 国产伦理精品 | av资源免费观看 | 国产伦精品一区二区三区网站 | 欧美成人黄色小说 | 国产黄色小视频在线观看 | 日韩中文电影 | 国内激情 | av在线亚洲天堂 | 久久国产精品免费观看 | 不卡av一区 | 国产精品久久国产精麻豆96堂 | 免费网站www在线观看 | 正在播放超嫩在线播放 | 久久这里都是精品 | 国产精品视频一二区 | 色视屏| 国产成人一区二区三区免费看 | 亚洲欧美韩国 | 在线观看国产小视频 | 天天夜夜啦啦啦 | 国产亚洲电影 | 香蕉视频免费在线观看 | 一级二级三级黄色片 | 超碰成人在线免费观看 | 久久久精品久久久 | www视频免费在线观看 | 国产精品久久久久久精 | 日本少妇高潮喷水xxxxxxx | 不卡av在线免费观看 | 蜜臀视频在线观看 | 中文欧美日韩 | 让男按摩师摸好爽视频 | 国产伦精品一区二区三区视频我 | 五月激情综合 | 国产自精品 | av黄色成人| 自拍偷拍日韩精品 | 天天干天天操心 | 麻豆偷拍| 伊人激情影院 | 日本乱码一区二区 | 在线看片a| 西西人体高清44rt·net | 小珊的性放荡羞辱日记 | 久久久久久久久久久久久久久久久久久久 | 国产欧美亚洲一区二区 | av色欲无码人妻中文字幕 | 日本激情在线 | 黄色大片在线 | 天天久久综合 | 久久天堂av | 2025av在线播放 | 免费黄色激情视频 |