NC236063. Hotpot
描述
输入描述
There are multiple test cases. The first line of the input contains an integer () indicating the number of test cases. For each test case:The first line contains three integers , and (, , ) indicating the number of tourists, the number of types of ingredients and the number of moves.The second line contains integers () where indicates the favorite ingredient of tourist .It's guaranteed that neither the sum of nor the sum of of all the test cases will exceed .
输出描述
For each test case output integers in one line separated by a space, where indicates the happiness value of tourist after moves.Please, DO NOT output extra spaces at the end of each line, or your answer might be considered incorrect!
示例1
输入:
4 3 2 6 1 1 2 1 1 5 1 2 2 10 1 2 2 2 10 1 1
输出:
0 2 1 2 2 2 0 5
C++ 解法, 执行用时: 20ms, 内存消耗: 768K, 提交时间: 2022-04-03 10:18:43
#include<bits/stdc++.h> using namespace std; const int maxn=10005; int T,n,m,k,ans[maxn],a[maxn],f[maxn]; int main(){ for (scanf("%d",&T);T;--T){ scanf("%d%d%d",&n,&k,&m); memset(f,0,sizeof(f)); for (int i=0;i<n;++i) scanf("%d",&a[i]),ans[i]=0; int t=m/(2*n); for (int i=0;i<2*n;++i){ if (!f[a[i%n]]) f[a[i%n]]=1;else{ if (m%(2*n)-1>=i) {ans[i%n]++;} f[a[i%n]]=0,ans[i%n]+=t; } } for (int i=0;i<n;++i) printf("%d%c",ans[i],i<n-1?' ':'\n'); } return 0; }