【比赛】USACO 20 Dec
文章目录
目前只有本人考场ac的题目,其他会随后补上
Bronze
A.Do You Know Your ABCs?
简单题
发现七个数加和正好是 4 ( A + B + C ) 4(A+B+C) 4(A+B+C),,我们得到了 A + B + C A+B+C A+B+C的值
枚举三个数,如果和为 A + B + C A+B+C A+B+C,直接升序输出即可
时间复杂度 O ( 7 3 ) O(7^3) O(73)
#include<bits/stdc++.h>
using namespace std;
inline int Read(){
int s = 0 , w = 1;
char ch = getchar();
while(ch > '9' || ch < '0'){
if(ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
s = (s << 1) + (s << 3) + ch - '0';
ch = getchar();
}
return s * w;
}
#define int long long
int a[10],sum;
#undef int
int main(){
#define int long long
for(int i = 1 ; i <= 7 ; i ++) a[i] = Read();
for(int i = 1 ; i <= 7 ; i ++) sum += a[i];
sum /= 4;
for(int i = 1 ; i <= 7 ; i ++){
for(int j = i + 1 ; j <= 7 ; j ++){
for(int k = j + 1 ; k <= 7 ; k ++){
if(sum == a[i] + a[j] + a[k]){
int s[10];
s[1] = a[i] , s[2] = a[j] , s[3] = a[k];
sort(s + 1,s + 3 + 1);
cout << s[1] << " " << s[2] << " " << s[3] << endl;
return 0;
}
}
}
}
return 0;
}
B. Daisy Chains
简单题
枚举区间,枚举区间中每一个点,如果这个点是这个区间的平均数则产生贡献
前缀和优化即可
时间复杂度 O ( n 3 ) O(n^3) O(n3)
#include<bits/stdc++.h>
using namespace std;
inline int Read(){
int s = 0 , w = 1;
char ch = getchar();
while(ch > '9' || ch < '0'){
if(ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
s = (s << 1) + (s << 3) + ch - '0';
ch = getchar();
}
return s * w;
}
const int MAXN = 1e4;
int n,ans;
int a[MAXN],sum[MAXN];
int main(){
n = Read();
for(int i = 1 ; i <= n ; i ++){
a[i] = Read();
sum[i] = a[i] + sum[i - 1];
}
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= n ; j ++){
for(int k = i ; k <= j ; k ++){
if(a[k] * (j - i + 1) == sum[j] - sum[i - 1]){
ans ++ ;
break;
}
}
}
}
cout << ans << endl;
return 0;
}
C.Stuck in a Rut
预处理出每个交点,按两头牛离交点的距离的较大值为关键字排序
距离大的显然不可能更新小的
离交点更近的牛会挡住更远的牛
扫一遍所有的交点即可
时间复杂度 O ( n 2 ) O(n^2) O(n2)
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f;
const int MAXN = 100;
struct cow{
int d,x,y,ans;
int stop;
}s[MAXN];
struct Pnt{
int x,y,tim,i,j;
}p[MAXN <