模拟赛#1 | USACO19 DEC Bronze

Posted IhopeIdieyoung

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模拟赛#1 | USACO19 DEC Bronze相关的知识,希望对你有一定的参考价值。

题目链接:
A https://www.luogu.com.cn/problem/P5831
B https://www.luogu.com.cn/problem/P5832
C https://www.luogu.com.cn/problem/P5832


A

分析: 范围很小, 直接暴力枚举即可, 每一对奶牛枚举看看是不是一致, 考察循环程序设计, 时间复杂度\\(O(n^2k)\\)

代码:

/*
Author: SJ
*/
#include<bits/stdc++.h>
const int N = 1e2 + 10;
using ll = long long;
using ull = unsigned long long;

int k, n, re[N][N];
int main() 
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	std::cin >> k >> n;
	for (int i = 1; i <= k; i++) 
		for (int j = 1; j <= n; j++) 
			int x;
			std::cin >> x;
			re[x][i] = j;
		
	
	ll ans = 0;
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= n; j++) 
			if (i != j) 
				bool flag = 1;
				for (int p = 1; p <= k; p++) 
					if (re[i][p] < re[j][p]) 
						flag = 0;
						break;
					
				
				if (flag) ans++;
			
		
	
	std::cout << ans;
	return 0;


B

分析: 继续暴力, 考察string相关函数, 字符串操作, 时间复杂度\\(O(n^3)\\)

代码

/*
Author: SJ
*/
#include<bits/stdc++.h>
const int N = 1e5 + 10;
using ll = long long;
using ull = unsigned long long;

int n;
std::string s1;
std::vector<std::string> v1;
int main() 
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	std::cin >> n >> s1;
	for (int k = n; k >= 1; k--) 
		for (int i = 0; i + k <= s1.size(); i++) 
			std::string s3 = s1.substr(i, k);
			// std::cout << s3 << \' \' << k << "\\n";
			for (auto i : v1) 
				if (s3 == i) 
					std::cout << k + 1;
					return 0;
				
			
			v1.push_back(s3);
		
	
	return 0;

C

分析: 用next_permutation可以直接秒的, 莫名其妙挖掘了一堆没用的性质, 然后上了个贪心(强行加大代码难度bushi

代码:

/*
Author: SJ
*/
#include<bits/stdc++.h>
const int N = 1e5 + 10;
using ll = long long;
using ull = unsigned long long;

std::string s[10] = 
	"Zeka", "Bessie", "Buttercup", "Belinda", "Beatrice", "Bella", "Blue", "Betsy", "Sue"
;
std::vector<int> g[10];
bool vis[N];
std::queue<int> q;
int query() 
	int head = 0;
	for (int i = 1; i <= 8; i++) 
		if (!vis[i] && s[i] < s[head] && g[i].size() <= 1) 
			head = i;
		
	
	return head;

bool cmp(int a, int b) 
	return s[a] < s[b];

void dfs(int x) 
	std::cout << s[x] << "\\n";
	vis[x] = 1;
	for (auto i : g[x]) 
		if (!vis[i]) 
			dfs(i);
		
	

int main() 
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n;
	std::cin >> n;
	for (int i = 1; i <= n; i++) 
		std::string s1, s2;
		std::cin >> s1;
		int mark = 5;
		while (mark--) std::cin >> s2;
		// std::cout << s1 << \' \' << s2 << "\\n";

		int mark1, mark2;
		for (int i = 1; i <= 8; i++) 
			if (s[i] == s1) mark1 = i;
			else if (s[i] == s2) mark2 = i;
		
		g[mark1].push_back(mark2);
		g[mark2].push_back(mark1);
	
	for (int i = 1; i <= 8; i++) std::sort(g[i].begin(), g[i].end(), cmp);
	for (int i = 1; i <= 8; i++) 
		int head = query();
		if (!head) break;
		dfs(head);
	
	return 0;

这个贪心很显然是对的

用next_permutation的代码:

咕咕咕

bzoj1648 / P2853 [USACO06DEC]牛的野餐Cow Picnic

P2853 [USACO06DEC]牛的野餐Cow Picnic

你愿意的话,可以写dj。

然鹅,对一个缺时间的退役选手来说,暴力模拟是一个不错的选择。

让每个奶牛都把图走一遍,显然那些被每个奶牛都走过的点就是符合条件的点。

技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 #define N 1002
 6 int val[N],in[N],k,n,m,ans;
 7 bool d[N][N],vis[N];
 8 void dfs(int x,int t){
 9     vis[x]=1; val[x]+=t;
10     for(int i=1;i<=n;++i)
11         if(d[x][i]&&!vis[i])
12             dfs(i,t);
13 }
14 int main(){
15     scanf("%d%d%d",&k,&n,&m);
16     for(int q,i=1;i<=k;++i)
17         scanf("%d",&q),++in[q];
18     for(int i=1,q1,q2;i<=m;++i)
19         scanf("%d%d",&q1,&q2),d[q1][q2]=1;
20     for(int i=1;i<=n;++i)
21         if(in[i]){
22             memset(vis,0,sizeof(vis));
23             dfs(i,in[i]);
24         }
25     for(int i=1;i<=n;++i)
26         if(val[i]==k) ++ans;
27     printf("%d",ans);
28     return 0;
29 }
View Code

 

以上是关于模拟赛#1 | USACO19 DEC Bronze的主要内容,如果未能解决你的问题,请参考以下文章

题解[USACO19DEC]Tree Depth

[USACO19DEC] Milk Visits(gold) 题解

BZOJ2097[Usaco2010 Dec] 奶牛健美操

[USACO19DEC]Tree Depth P

luoguP5836 [USACO19DEC]Milk Visits S

[USACO19DEC]Milk Visits S(LCA)