微网站开发系统,51找呀模板网,网站底部加编码,省市建设类网站链接题目描述及代码如下。
我使用模拟打表法#xff0c;示例通过了#xff0c;但是提交通过率为0。诚心求教。欢迎补充题目#xff0c;或者有原题链接更好~。我觉得可能出错的点#xff1a;int - long long ?或者一些临界条件。
/*
美团25毕业秋招第三题#xff0c;做题…题目描述及代码如下。
我使用模拟打表法示例通过了但是提交通过率为0。诚心求教。欢迎补充题目或者有原题链接更好~。我觉得可能出错的点int - long long ?或者一些临界条件。
/*
美团25毕业秋招第三题做题时间2024 8 10有一根无限长度、颜色循环的彩带彩带的颜色为N对彩带进行 k次剪裁。
求每次剪裁下来的彩带中有多少种颜色。6 3彩带长为6进行3次剪裁
1 2 3 4 1 4 彩带颜色
L 2 第一次剪裁从左边开始剪裁长度为2 因此颜色数是 2从1剪到212两种
L 3 第二次剪裁从左边开始剪裁长度为3 因此颜色数是 3从3剪到1341两种
R 12 第三次剪裁从右边开始剪裁长度为12颜色是整个band的颜色共4种
这个实例我修改过只是为了解释题意印象中 N k 都是1e9
别的条件不记得了欢迎补充
*/#include iostream
#include algorithm
#include vector
#include map
#include unordered_map
#include string
#include set
using namespace std;
int main()
{int BanLength, cutTimes;cin BanLength cutTimes;vectorint BanColor(BanLength);for (int i 0; i BanLength; i)cin BanColor[i];vectorvectorint rec(BanLength, vectorint(2 * BanLength, 1));for (int i 0; i BanLength - 1; i){for (int j i 1; j 2 * BanLength; j){if (j - i BanLength){rec[i][j] rec[0][BanLength - 1];continue;}int colorNum 0;setint ColorApps;for (int k i; k j; k){if (ColorApps.find(BanColor[k % BanLength]) ColorApps.end()){colorNum;ColorApps.insert(BanColor[k % BanLength]);}}rec[i][j] colorNum;}}// cout REC 0 1 rec[0][1] endl;char direc;int lengthCut;vectorpairchar, int everyCut(cutTimes);for (int i 0; i cutTimes; i){cin direc lengthCut;everyCut[i] pairchar, int(direc, lengthCut);}int left 0, right BanLength - 1;int start, end;for (int i 0; i cutTimes; i){if (everyCut[i].second BanLength){cout rec[0][BanLength - 1] endl;continue;}if (everyCut[i].first L){start left;end left everyCut[i].second - 1;// cout out:rec[ start , end ] endl;cout rec[start][end] endl;left (end 1) % BanLength;}else{end right;start right - everyCut[i].second 1;while (start 0){start BanLength;end BanLength;}// cout out:rec[ start , end ] endl;cout rec[start][end] endl;right start - 1;while (right 0)right BanLength;}}return 0;
}