I'm Bored! Gym
阿新 • • 發佈:2018-12-20
- 題意:給定一個26個字母的個數,要求能組成最長迴文串的長度,與最長長度的個數,(迴文串中每種字母<=2)
- 思路:判斷一下>=2的個數與==1的個數即可
-
#include<bits/stdc++.h> using namespace std; #define maxn 30 #define inf 0x3f3f3f3f #define ll long long ll a[maxn],t,s1,s2,minn,ans,sum; int main() { scanf("%lld",&t); while(t--) { minn=1e12; ans=s1=s2=sum=0; for(int i=1; i<=26; i++) { scanf("%lld",&a[i]); if(a[i]==1)s1++; if(a[i]>=2) { s2++; minn=min(a[i]/2,minn); } } ans=s2*2; if(s1>0) { ans++; sum=min(minn,s1); } else sum=minn; if(minn==1e12)sum=s1; printf("%lld %lld\n",ans,sum); } return 0; }