虽说是退役了,但是上分这种事还是放不下滴,有空打打比赛,锻炼下智商
题目链接:
A. Silent Classroom
统计相同首字母的单词数目,然后每个字母群的最小分组为num*(num-1)/2;
参考代码:
//include <bits/stdc++.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <time.h>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 10007;
const int maxn = 2*1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
template <class T>
inline bool scan_d(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
int n;
int num[30];
int main()
{
memset (num,0,sizeof(num));
scanf("%d",&n);
for (int i=0;i<n;i++)
{
char s[105];
scanf("%s",s);
num[s[0]-'a']++;
}
ll sum=0;
for (int i=0;i<30;i++)
{
if(num[i]>0)
{
int t=num[i]/2;
sum =sum+t*(t-1)/2;
t=num[i]-t;
sum =sum+t*(t-1)/2;
}
}
printf("%lld\n",sum);
return 0;
}
B. All the Vowels Please
给出的数k只要分解的n,m都大于5,则就可以组成,答案就是排出5*5矩阵之后每一行多出的随便补就行了。
代码如下:
//include <bits/stdc++.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <time.h>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 10007;
const int maxn = 2*1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
template <class T>
inline bool scan_d(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
int k;
char a[6][10]={"aeiou","eioua","iouae","ouaei","uaeio"};
int main()
{
//a[0]="aeiou";
//a[1]="eioua";
//a[2]="iouae";
//a[3]="ouaei";
//a[4]="uaeio";
scanf("%d",&k);
int n=0,m=0,flag=0;
for (int i=5;i<=k;i++)
{
if(k%i==0)
{
n=i;
m=k/i;
if(m>=5)
{
flag=1;
break;
}
}
}
if(flag==0)
{
printf("-1\n");
}
else
{
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
printf("%c",a[i%5][j%5]);
}
//printf("\n");
}
printf("\n");
}
return 0;
}
C. A Tale of Two Lands
打表发现了规律,固定X,只要是X/2+X%2=<Y<=2*X(可互换位置),-(X/2+X%2)=<Y<=-(2*X)(可互换位置),二分查找上界和下界即可。
代码如下:
//include <bits/stdc++.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <time.h>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 10007;
const int maxn = 2*1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
template <class T>
inline bool scan_d(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
int n;
ll a[maxn];
vector<ll>z,f;
int num=0;
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
if(a[i]>0)
{
z.push_back(a[i]);
}
else if(a[i]<0)
{
f.push_back(-a[i]);
}
else
{
num++;
}
}
ll sum=0;
sort(z.begin(),z.end());
sort(f.begin(),f.end());
for (int i=1;i<=n;i++)
{
if(a[i]!=0)
{
if(a[i]<0) a[i]=-a[i];
int loca,locb;
loca=upper_bound(z.begin(),z.end(),a[i]*2)-z.begin();
locb=lower_bound(z.begin(),z.end(),a[i]/2+a[i]%2)-z.begin();
sum=sum+loca-locb;
loca=upper_bound(f.begin(),f.end(),a[i]*2)-f.begin();
locb=lower_bound(f.begin(),f.end(),a[i]/2+a[i]%2)-f.begin();
sum=sum+loca-locb;
sum--;
}
}
sum/=2;
sum =sum+(num)*(num-1)/2;
printf("%lld\n",sum);
return 0;
}