補: Codeforces Round #698 (Div. 2)
阿新 • • 發佈:2021-01-30
技術標籤:演算法導論
補: Codeforces Round #698 (Div. 2)
喵喵喵,比賽太呆了!!!
A題交錯檔案WA了一次,B題居然錯在了一個小點上,錯失了上大分的機會。
QwQ,下次一定!
文章目錄
A - Nezzar and Colorful Balls
求最長重複序列的長度。
#include<bits/stdc++.h>
#define PI acos(-1)
#define endl "\n"
#define mm(a, b) memset(a, b, sizeof(a))
#define debug freopen("1.in", "r", stdin), freopen("1.out", "w", stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair< int , int> PII;
int t , n;
const int N = 200;
int a[N];
int main()
{
cin >> t;
while(t --)
{
cin >> n;
int cnt = 1;
int maxx = 1;
for(int i = 0;i < n;i ++)
{
cin >> a[i];
if(i == 0)continue;
if(a[i] == a[i - 1])cnt ++;
else cnt = 1;
maxx = max(maxx, cnt);
}
cout << maxx << endl;
}
return 0;
}
B - Nezzar and Lucky Number
注意的是,>=d *10 的時候,肯定是YES,拿7舉例子,到70的時候,說明,71,72,73,74,75 ···· 79,都解鎖了,想拼什麼都可以拼出來。
(比賽後改了一行程式碼就過了,丟!)
#include<bits/stdc++.h>
#define PI acos(-1)
#define endl "\n"
#define mm(a, b) memset(a, b, sizeof(a))
#define debug freopen("1.in", "r", stdin), freopen("1.out", "w", stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int , int> PII;
int t , n;
const int N = 200;
int a[N];
int main()
{
cin >> t;
while(t --)
{
cin >> n;
int cnt = 1;
int maxx = 1;
for(int i = 0;i < n;i ++)
{
cin >> a[i];
if(i == 0)continue;
if(a[i] == a[i - 1])cnt ++;
else cnt = 1;
maxx = max(maxx, cnt);
}
cout << maxx << endl;
}
return 0;
}