首页 > 其他分享 >Educational Codeforces Round 124 (Rated for Div. 2)

Educational Codeforces Round 124 (Rated for Div. 2)

时间:2023-04-07 14:35:37浏览次数:49  
标签:Educational Rated int 1e10 Codeforces long cin define

题目链接

C

核心思路

其实还是得根据样例,首先我们先自己分析出来。现根据边地数目来分析。

我们其实不难发现四个端点必须得连上边。

  1. 边数为2.那么只有两条竖线。方案数是一种
  2. 边数为3,那么就一条竖线还有就是一把叉这里交换位置就是两条了。还有就是平行四边形和一条斜线,也是可以交换位置的。这里就有四种。
  3. 边数为4.这个就可以发现就是两把叉就好了。方案数是一种。

所以综上就这么些情况,还是不难的。

// Problem: C. Fault-tolerant Network
// Contest: Codeforces - Educational Codeforces Round 124 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1651/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define NO {puts("NO") ; return ;}
#define YES {puts("YES") ; return ;}
#define endl "\n"
#define int long long 

const int N=2e5+10;
int a[N],b[N];


void solve()
{
	int n;
	cin>>n;
	int a1=1e10,an=1e10,b1=1e10,bn=1e10;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=1;i<=n;i++)
	cin>>b[i];
	int ans=abs(a[1]-b[1])+abs(a[n]-b[n]);
	for(int i=1;i<=n;i++)
	{
		a1=min(a1,abs(a[1]-b[i]));
		b1=min(b1,abs(a[i]-b[1]));
		
		an=min(an,abs(a[n]-b[i]));
		bn=min(bn,abs(b[n]-a[i]));
		
	}
	ans=min(ans,a1+b1+an+bn);
	ans=min(ans,a1+b1+abs(a[n]-b[n]));
	ans=min(ans,an+bn+abs(a[1]-b[1]));
	ans=min(ans,abs(a[1]-b[n])+an+b1);
	ans=min(ans,abs(a[n]-b[1])+a1+bn);
	ans=min(ans,abs(a[1]-b[n])+abs(b[1]-a[n]));
	cout<<ans<<endl;
	
	
	
	
	
	
}


signed main()
{
int t;
cin>>t;
while(t--)
{
	solve();
}
}

D

核心思路

其实我们可以发现一个结论,那就是最终地答案一定就是每个已经知道的点地周边的点。所以这个题目就很好做了。

我们首先把周边地点全都入手,然后以周边的作为起点来所有其他已经知道的点。我们可以数形结合把这个理解为一个一个雷达,他们首先是进行半径为1地搜索,然后是半径为2地,一次类推.....。

我们不难发现这样一定是正确的,因为边权都是1.

#include <bits/stdc++.h>

using namespace std;

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
typedef pair<int,int> PII;


int main()
{
	int n;
	cin>>n;
	vector<PII> a(n);
	for(auto &[x,y]:a)
	{
		cin>>x>>y;
	}
	set<PII> st(a.begin(),a.end());//判重
	map<pair<int,int>,pair<int,int>> ans;
	queue<PII> q;
	for(auto [x,y]:a)
	{
		for(int i=0;i<4;i++)
		{
			int tx=x+dx[i];
			int ty=y+dy[i];
			if(!st.count({tx,ty}))
			{
				ans[{x,y}]={tx,ty};
				q.push({x,y});
				break;//只要找到一个这样的点就好了。
			}
			
		}
	}
	while(q.size())
	{
		auto t=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			int x=t.first;
			int y=t.second;
			int tx=x+dx[i],ty=y+dy[i];
			if(!st.count({tx,ty})||ans.count({tx,ty}))
			continue;
			ans[{tx,ty}]=ans[{x,y}];
			q.push({tx,ty});
		}
	}
	for(auto [x,y]:a)
	{
		auto it=ans[{x,y}];
		cout<<it.first<<" "<<it.second<<endl;
	}
	return 0;
	
	
	
	
	
	
}

标签:Educational,Rated,int,1e10,Codeforces,long,cin,define
From: https://www.cnblogs.com/xyh-hnust666/p/17296031.html

相关文章

  • [CodeForces]4.7
    题目链接:https://codeforces.com/contest/1610/problem/E灵神描述输入t(≤1e4)表示t组数据。所有数据的n之和≤2e5。每组数据输入n(2≤n≤2e5)和长为n的有序数组a(1≤a[i]≤1e9),有重复元素。你需要从a中删除一些元素,对于a的任意非空子序列b,都必须满足:设avg为......
  • CodeForces - 149D Coloring Brackets(区间DP)
    题目大意:给你一个符合括号规则的字符串,现在要求你将这些括号染色,染色规则如下1.一个括号要么被染成红色,要么被染成蓝色,要么不染2.相邻的括号的颜色不能相同(可以同为无色)3.成对的括号只能有一个被染色问染色的方案数解题思路:0表示不染,1表示红色,2表示蓝色那么成对的括号......
  • codeforces 1793D Moscow Gorillas
    https://codeforces.com/contest/1793/problem/D解题思路依次找出MEX=1..n+1的序列数量就能得解。MEX=n+1只有全序列这一种情况。MEX=1时,找出两个序列中1的位置,较小位置左边的元素构成的子序列,较大位置右边的元素构成的子序列,以及两个位置中间的元素构成的子序列都满......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)(持续更新)
    Preface唉难得熬夜打一把还天天掉分,苦路西这把状态奇差,CD两个傻逼题都写的很慢,然后做E的时间太少最后又是经典比赛结束才调出来虽然很想骂傻逼室友打游戏鬼叫的超级响导致我注意力很难集中,不过终究还是自己抗干扰水平不够,不能怨天尤人A.BeautifulSequence傻逼题,显然若一个......
  • Codeforces Round 642 (Div3)
    K-periodicGarland给定一个长度位\(n\)的\(01\)串,每次操作可以将\(1\)变为\(0\)或者将\(0\)变为\(1\),现在你需要通过操作使得所有\(1\)之间的距离为\(k\),求最少的操作次数,注意全为\(0\)也算\(1<=n<=1e6,1<=k<=n\)\(dp\)/贪心:最大子段和思想方法一:\(dp\)\(O(n)\)状......
  • codeforces 1795E Explosions?
    https://codeforces.com/problemset/problem/1795/E解题思路问题的核心是要构造有一个先严格递增,然后严格递减的子序列。不在这个序列中的怪物单独击杀。先递增后递减可以看作是两个对称的问题,所以把递增序列的构造考虑清楚就可以了。假设已经知道将1~i-1构造成严格递增子序列所......
  • Codeforces Round 862 (Div. 2)
    CodeforcesRound862(Div.2)链接CodeforcesRound862(Div.2)A题#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<vector>#include<cstring>#include<unordered_set>#includ......
  • Codeforces Round 863 (Div. 3)
    CodeforcesRound863(Div.3)链接CodeforcesRound863(Div.3)A题遍历这个字符串,如果要插入的数第一次小于当前的数,就将数插入到这里,如果到最后都没有插入数,插入到最后#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<vec......
  • Codeforces Round 863 (Div. 3) E题
    题目地址题意:定义数组a包含所有不含数字4的正整数,给出一个n,要求求出数组a中第n个数Solution数位dp+二分,求出[1,mid]中不含数字4的正整数个数,不过因为有可能mid包含4,但是由于贡献是一样的,可以直接把4都变成3,最后处理一下即可intdp[20];inta[20];voidinit(){ dp[0]=1; f......
  • Codeforces Round 863 (Div. 3)
    A.InsertDigit放在第一个比他小的数前面#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn,d;cin>>n>>d;strings;cin>>s;for(chari:s){if(d>i-'0')cout<<d,d......