Codeforces Round #546 div.2 B,C

第一次熬夜打cf,感觉确实脑子不灵光了. 再加上边界条件确实考虑不周全.
写下我的wa题思路吧

B

  • 题意: 一排洞,每个洞下面有一个金币,上面有一个石头,需要将所有的金币取出,且只有将石头移开才能取金币
    移动,移动石头,取金币都花费1
  • 思路: 根据暴力加模拟的思想,分析样例可知在经历过前两个洞之后,每个洞只需要走,移,取 三步.
    前两个洞需要有一个洞空出来,来供后面的洞来放石头,一侧的石头处理完后便移动到开头来处理另一侧.

#include<bits/stdc++.h> 

#define ll long long 

#define inf 0x3f3f3f3f
using namespace std; 

const int maxn = 1e5+10;

int n,k;
int main(){
	cin >> n >> k;
	if(k==n || k==1)
		cout << (n-2)*3+6 << endl;
	else
//		cout << (n-2)*3+6+k-1 << endl;
	{
//		int ans = 6;
//		for(int i=k-1;i>1;--i)	ans+=3;
//		ans += k-1;
//		for(int i=k+1;i<=n;++i)	ans+=3;
//		cout << ans << endl;
//		k = min(n-k,k);
		int ans = (n-2)*3+6-1;
		if(k>n/2){
			ans += (n-k)+1;
		}else{
			ans += k;
		}
		cout << ans << endl;
	}
//	if(n-k==1 || k==1)
//	{
//	cout << (n-2)*3+6 << endl;
//	}
//	else if(n==2)
//			cout <<6 << endl;
//		else
//			cout << (n-2)*3+7 << endl;
	return 0;
}

注释掉的代码,是我走过的心路旅程

首先(k=n)(k=1)是等价的 都不需要再从一侧移动回来
当k>n/2,我们移动的距离是((n-k)+1)的半段
总体来说还是很简单的

C

  • 题意: 给一个矩阵,可以进行任意大小任意次数的转置,
    问是否能变化成另一个矩阵
  • 思路: 副对角线是联通的,只需判断每个联通集是否完全相对
#include<cstdio>
#include<deque>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<stack>
#include<map>
#define ll long long 

#define inf 0x3f3f3f3f
using namespace std; 
int n,m;
const int maxn = 510;

int a[maxn][maxn];
int b[maxn][maxn];

vector<int> aa;
vector<int> bb;
map<int,int> ma;
map<int,int> mb;
int vis[maxn*maxn];
int main(){
	cin >> n >> m;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)	scanf("%d",&a[i][j]);
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)	scanf("%d",&b[i][j]);
	}
	for(int i=2;i<=m+n+1;++i){
		ma.clear();
		mb.clear();
		for(int j=1;j<i;++j){
			int k = i-j;
			if(j>n || k>m)	continue;
			ma[a[j][k]]++;
			mb[b[j][k]]++;
		}
		for(auto j:ma){
			if(mb[j.first]!=j.second){
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

这题错的更惨
最后两分钟交了一发ac了,结果赛后重判又给wa了,原因是原来map的计数有问题,不能解决联通集有重复元素的情况.
而且一开始输入用的cin老是TLE QAQ

收获:

  1. 数据大,读入优化(这道题输入是1e6的)
  2. map判断集合相等,只需要把每个值加入到map中,然后判断second(出现次数)是否相等.

其实这两题都非常的简单,wa题的关键在于细节没有控制好吧

原文地址:https://www.cnblogs.com/xxrlz/p/10520019.html