

很遗憾,这次cf爆零了,我在第一题上花了好长时间,可是就是没想出解决方法,题目是说要给不同编号的球染色,求最少需要多少种颜色。
AC代码如下:
#include<iostream>
using namespace std;
typedef long long ll;
ll read(){
char ch = getchar();
ll x = 0, f = 1;
while(ch < '0' && ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int a[2500000];
int main(){
int n = read();
for(int i = 1; i <= n; i++){
int m = read();
int mx = 1, sum = 0;
for(int i = 1; i <= m; i++){
a[i] = read();
if(a[i] == a[i-1]){
sum++;//如果编号相同,就需要加一种颜色
mx = max(sum, mx);//并更新需要的总颜色数
}
else sum = 1;//否则,当前的球只需要一种颜色,不需要更新总颜色数。
}
cout << mx << endl;
}
return 0;
}
最后
以上就是典雅小兔子最近收集整理的关于统计连续数字的个数的全部内容,更多相关统计连续数字内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复