USACO 2018 December Contest Bronze 题解

4 篇文章 0 订阅
4 篇文章 0 订阅

T1 Mixing Milk

【题意】

给你三个桶和他们的容量和现在装了多少,问倒奶100次之后变成什么样(不能倒出来)

【分析】

铜组题都水的要死,这题肯定红题啊,怎么会是绿题呢?

才100次,很明显是模拟题。

我们直接枚举怎么倒

假设倒1桶和2桶,那么能够倒出来的量 s u m = m i n ( b [ 1 ] , a [ 2 ] − b [ 2 ] ) sum=min(b[1],a[2]-b[2]) sum=min(b[1],a[2]b[2]),即当前1的桶内量和b桶还可以放多少。

其他两种倒法类似。

总共100次,为 33 ∗ ( 1 − > 2 ) + 33 ∗ ( 2 − > 3 ) + 33 ∗ ( 3 − > 1 ) + 1 − > 2 33*(1->2)+33*(2->3)+33*(3->1)+1->2 331>2+33(2>3)+33(3>1)+1>2

余下来再处理一次 1 − > 2 1->2 1>2,就AC了。

#include <bits/stdc++.h>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 10 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
    char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
    cout << x << endl ;
    exit(0) ;
}

void PRINT(string x) {
    cout << x << endl ;
    exit(0) ;
}

void douout(double x){
     printf("%lf\n", x + 0.0000000001) ;
}

int n ;
int a[N], b[N] ;

int main() { 
	n = 3 ; 
	for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]) ;
	for (int rnd = 1, tmp; rnd <= 33; rnd++) {
		tmp = b[1] ;
		if (tmp > a[2] - b[2]) tmp = a[2] - b[2] ;
		b[1] -= tmp ; b[2] += tmp ;
		
		tmp = b[2]  ;
		if (tmp > a[3] - b[3]) tmp = a[3] - b[3] ;
		b[2] -= tmp ; b[3] += tmp ;
		
		tmp = b[3] ;
		if (tmp > a[1] - b[1]) tmp = a[1] - b[1] ;
		b[3] -= tmp ; b[1] += tmp ;
	}
	int tmp = b[1] ;
	if (tmp > a[2] - b[2]) tmp = a[2] - b[2] ;
	b[1] -= tmp ;
	b[2] += tmp ;
	printf("%d\n%d\n%d\n", b[1], b[2], b[3]) ;
} 

T2 The Bucket List

【题意】

有n只奶牛,每头奶牛 i i i会在 s [ i ] s[i] s[i]时刻索要 b [ i ] b[i] b[i]个桶,然后在 t [ i ] t[i] t[i]时归还,请问要准备几个同才能满足要求。

【分析】

水题一道

搞个 s t r u c t ( t i m , o p , s u m ) struct(tim,op,sum) struct(tim,op,sum),表示在 t i m tim tim时刻发生的时间, o p op op表示属性,0为索要,1为归还, s u m sum sum表示数量。这样会有 2 n 2n 2n s t r u c t struct struct

s t r u c t struct struct t i m tim tim排个序,然后 f o r for for一遍处理一下就可以了。

【代码】

#include <bits/stdc++.h>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 110 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
    char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
    cout << x << endl ;
    exit(0) ;
}

void PRINT(string x) {
    cout << x << endl ;
    exit(0) ;
}

void douout(double x){
     printf("%lf\n", x + 0.0000000001) ;
}

int n, ans, res, cnt ;

struct events {
	int tim, ch, sum ;
} a[N << 1] ;

bool cmp(events a, events b) {
	return a.tim < b.tim ;
}

int main() {
	scanf("%d", &n) ;
	for (int i = 1, s, t, b; i <= n; i++) {
		scanf("%d%d%d", &s, &t, &b) ;
		a[++cnt] = (events) {s, 0, b} ;
		a[++cnt] = (events) {t, 1, b} ;
	}
	sort(a + 1, a + cnt + 1, cmp) ;
	for (int i = 1; i <= cnt; i++) {
		events tmp = a[i] ;
		if (tmp.ch == 0) ans += tmp.sum ;	
		else ans -= tmp.sum ;
		res = max(res, ans) ; 
	}
	printf("%d\n", res) ;
}

T3 Back and Forth

【题意】

有两个10个元素的数组A和B,你可以进行四次操作,每次操作你可以讲A或B中的一个一个元素移到另一个数组中(可以移动原来移动过的),问最终A的元素和有几种可能性。

【分析】

dfs肯定没脑子而且时间复杂度过得去,但是好像移动元素比较费劲,我们考虑直接枚举移动元素。

首先要分一下讨论。

  1. 两个回合B都把上次A移过来的移会去,答案肯定为0
  2. 有一个回合B都把上次A移过来的移会去,枚举剩下一回合A和B移啥
  3. 没有一个回合B都把上次A移过来的移会去,枚举两个回合。

注意两个细节。一个是答案可能有重复,要记录去重;二是答案可能会有负数,要加上一个相对大的数。

然后就做完了。

【代码】

#include <bits/stdc++.h>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;
typedef multiset <int> si ;

const int N = 100010 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
    char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
    cout << x << endl ;
    exit(0) ;
}

void PRINT(string x) {
    cout << x << endl ;
    exit(0) ;
}

void douout(double x){
     printf("%lf\n", x + 0.0000000001) ;
}

int vis[N << 1], a[20], b[20] ;
int n, ans ;

int main() {
	n = 10 ;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]) ;
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]) ;
	ans = 1 ; vis[0 + N] = 1 ;
	for (int i = 1; i <= n; i++)  // 有一回合拿过来又送回去的 
	for (int j = 1; j <= n; j++)
	if (!vis[b[j] - a[i] + N]) vis[b[j] -a[i] + N] = 1, ans++ ;
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++)
	for (int ii = 1; ii <= n; ii++)
	for (int  jj = 1; jj <= n; jj++) 
	if (ii != i && jj != j) 
	if (!vis[b[j] - a[i] + b[jj] - a[ii] + N]) vis[b[j] - a[i] + b[jj] - a[ii] + N] = 1, ans++ ;
	printf("%d\n", ans) ;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值