标签:using out i++ else 删除 mat queue 判断 ios
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#define ll long long
#define FOR(i,n) for(int i =1; i <= n;++i )
#define FOR0(i,n) for(int i =0; i < n;++i )
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 2e5+10;
char buf[maxn];
char ans[maxn];
int n;
int main(){
cin >> n;
if(n==0){
cout << 0 << endl << endl;
exit(0); //长度为0
}
cin >>buf;
int cur = 0;
for(int i=0;i<n;++i){
if(cur%2==0){
while(buf[i+1]==buf[i]) i++;
}
ans[cur++] = buf[i];
}
ans[cur] = 0;
int ccur =cur;// 保证长度为偶数
ccur= ccur/2*2;
ans[ccur] = 0;
cout << n-ccur<<endl<<ans <<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define ll long long
#define FOR(i,n) for(int i =1; i <= n;++i )
#define FOR0(i,n) for(int i =0; i < n;++i )
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 310;
ll a[maxn];
int n;
ll cans;
int judge(){
if(n==1){
cans = a[1]*(ll)a[1];
return 1;
}
cans = a[1]*1LL*a[n];
for(int i=2;i<=n/2;++i){
if(a[i]*a[n-i+1]!=cans) return 0;
}
if(n%2==1 && a[n/2+1]*a[n/2+1]!=cans) return 0; //当n为奇数 特判中间数的平方
return 1;
}
int main(){
int orz;
cin >> orz;
while(orz--){
cin >> n;
FOR(i,n){
cin >> a[i];
}
sort(a+1,a+1+n);
if(judge()!=0){
int cnt = 0;
for(ll i=2;i*i<cans;++i){
if(cans%i==0){
cnt++;
// cout << i << endl;
}
}
cnt*=2;
if((ll)sqrt(cans)*(ll)sqrt(cans)==cans) cnt++;
if(cnt==n) cout << cans << endl;
else cout << -1 << endl;
}else{
cout << -1 <<endl;
}
}
return 0;
}
Codeforces Round #560 div3 (C,D)
标签:using out i++ else 删除 mat queue 判断 ios
原文地址:https://www.cnblogs.com/xxrlz/p/10868842.html