第一行给出三个正整数M(≤1000)、N和S,分别是转发总数、跳过的赢家数和第一个赢家的索引(索引从1开始)
如果有重复就跳过
#include <bits/stdc++.h>
using namespace std;
int main(){
int n1,n2,n3;
cin>>n1>>n2>>n3;
vector<string> arr(n1),res;
for(int i=0;i<n1;i++){
cin>>arr[i];
}
for(int i=n3-1;i<n1;i+=n2){
auto it=find(res.begin(),res.end(),arr[i]);
while(it!=res.end()){
i++;
it=find(res.begin(),res.end(),arr[i]);
}
res.push_back(arr[i]);
}
for(auto item:res)printf("%s\n",item.c_str());
if(res.empty())printf("Keep going...\n");
}
本文介绍了一种算法,该算法从给定的转发总数中选择赢家,但会跳过已经选中的重复项,确保每个赢家都是唯一的。首先读取转发总数、跳过的赢家数和第一个赢家的索引,然后遍历所有条目,使用循环和查找函数来避免重复,最终输出所有不重复的赢家。
446

被折叠的 条评论
为什么被折叠?



