Codeforces Round #614 (Div. 2)(A~E)

准备练习题解用蹩脚的英语和汉语写上两份,英语那份可能前期参照cf官方的toturial一段时间

比赛:传送门

A. ConneR and the A.R.C. Markland-N

题面:传送门
大意(zh):给出 n n n个楼层,目前你在 s s s楼,每个楼层都有一个餐厅,但是当下有 k k k个餐厅关门了,接着下一行给出关门餐厅的楼层号,一共有 k k k个。
大意(en):You are currently in the building with n n n floors numbered from 1 1 1 to n n n. There is a restaurant on each floor. But right now, k restaurants are closed. The second line of a test case contains k k k distinct integers a 1 , a 2 , . . . , a k a1,a2,...,ak a1,a2,...,ak – the floor numbers of the currently closed restaurants.
题解(zh):抓主题目关键部分,It is guaranteed that the sum of 𝑘 over all test cases does not exceed 1000. 这句话说出来的意思就是可以贪心的从近往远找,最多每个样例找 1000 1000 1000次而已。
题解(en):We should focus on key parts of the topic. It is guaranteed that the sum of 𝑘 over all test cases does not exceed 1000. It means that you can be greedy from near to far. Find 1000 1000 1000 per sample at most.
c o d e : code: code:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
int n,s,k;
int main()
{
    rush(){
		sc2(n,s);sc(k);
		map<int,int>m;
		rep(i,1,k){
			int x;
			sc(x);
			m.insert({x,1});
		}
		bool flag=false;
		rep(i,0,1001){
			if(s-i>=1&&m.find(s-i)==m.end()){
				printf("%d\n",i);
				flag=true;
				break;
			}else if(s+i<=n&&m.find(s+i)==m.end()){
				printf("%d\n",i);
				flag=true;
				break;
			}
		}
 
	}
    return 0;
}

B. JOE is on TV!

题意:传送门
大意(zh): 1 1 1 vs n n n的游戏,聚会中来了 n n n个朋友,你用问题难住他们,每局假设共有 a a a人,有 b b b人答错并且之后会被淘汰,本局你会获得 b a \frac{b}{a} ab的钱。问最多可能获得多少钱。
大意(en):Welcom the ‘1 vs n’ game, there are n friends at the party. You befuddled them with questions. Let’s say have a people per game. There are b b b people answer wrong and will be eliminated later. And you will receive b a \frac{b}{a} ab money. Ask how much you can get from the whole game?
题解(zh):直接盲猜 1 + 1 / 2 + ⋯ + 1 / n 1+1/2+\dots+1/n 1+1/2++1/n,正确性还未证明。
题解(en):Please blind guess 1 + 1 / 2 + ⋯ + 1 / n 1+1/2+\dots+1/n 1+1/2++1/n,Correctness has not been proved.
c o d e : code: code:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int n;
int main()
{
    sc(n);
	db ans=1;
	rep(i,2,n)ans+=1.0/i;
	printf("%.4f\n",ans);
    return 0;
}

C. NEKO’s Maze Game

题意:传送门
大意(zh):有个 2 ∗ n 2*n 2n 2 D 2D 2D平面,现在给出 q q q个动作,每个动作给出 ( r , c ) (r,c) (r,c),之后会翻转这个 ( r , c ) (r,c) (r,c),翻转奇数次不能通过,翻转偶数词可以通过,问每次动作后这个人还能从 ( 1 , 1 ) (1,1) (1,1) ( 2 , n ) (2,n) (2,n)么。
大意(en):There are a 2 ∗ n 2*n 2n 2 D 2D 2D plane. Now the god going to do q q q actions, there is a ( r , c ) (r,c) (r,c) on each action. We will flip this. You can’t pass when this is an odd number of times, but you can pass when this is an even number of times. Ask Can the person from ( 1 , 1 ) (1,1) (1,1) to (2,n) after each motion.
题解(zh):我的做法是这样的,考虑如何会堵住道路,当下面的一个 c e l l cell cell和上面与之相邻的三个 c e l l s cells cells都翻了奇数次才会堵住道路,另外加入了两个特判 ( 1 , 1 ) ( 2 , n ) (1,1) (2,n) (1,1)(2,n),然后用一个全局变量维护当前堵了多少,第 2 2 2排的每个位置用 s e t set set维护哪里堵了。
题解(en):Here’s how i do it, consider how to block the road, the next cell and the next three cells must both be turned an odd of times to block the road. Two additional special judgments were added (1,1)(2,n). A global variable is then used to maintain how much ways is currently blocked. Every position in 2rd row is blocked with s e t set set to maintenance.
c o d e : code: code:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=1e5+5;
int sum;
set<int>v[N];
bool flag1[N],flag2[N];
int n,q;
int main()
{
    sc2(n,q);
	int r,c;
	bool tepan1=true,tepan2=true;
	rep(i,1,q){
		sc2(r,c);
		if(r==1){
			if(c==1){
				if(tepan1)tepan1=false;
				else tepan1=true;
			}
			if(flag1[c]){
				if(c-1>=1){
					v[c-1].erase(c);
					if(flag2[c-1])sum--;
				}
				v[c].erase(c);
				if(flag2[c])sum--;
				if(c+1<=n){
					v[c+1].erase(c);
					if(flag2[c+1])sum--;
				}
				flag1[c]=false;
			}else{
				if(c-1>=1){
					v[c-1].insert(c);
					if(flag2[c-1])sum++;
				}
				v[c].insert(c);
				if(flag2[c])sum++;
				if(c+1<=n){
					v[c+1].insert(c);
					if(flag2[c+1])sum++;
				}
				flag1[c]=true;
			}
		}else{
			if(c==n){
				if(tepan2)tepan2=false;
				else tepan2=true;
			}
			if(flag2[c]==false){
				sum+=v[c].size();
				flag2[c]=true;
			}else{
				sum-=v[c].size();
				flag2[c]=false;
			}
		}
		if(sum||!tepan1||!tepan2)puts("No");
		else puts("Yes");
	}
    return 0;
}

D. Aroma’s Search

题意:传送门
大意(zh):在一个无穷的平面上有一种呈线性规律出现的点,关系如下: ( x i , y i ) = ( a x ∗ x i − 1 + b x , a y ∗ x i − 1 + b y ) (x_i,y_i)=(a_x*x_{i-1}+b_x,a_y*x_{i-1}+b_y) (xi,yi)=(axxi1+bx,ayxi1+by),现在给出你的起始点 ( x s , y s ) (x_s,y_s) (xs,ys),然后你可以在这个平面上最多停留 t t t秒,问你最多采集多少个这种规律点?
大意(en):There is a point on an infinite plane that appears as a linear law.The law is as follows: ( x i , y i ) = ( a x ∗ x i − 1 + b x , a y ∗ x i − 1 + b y ) (x_i,y_i)=(a_x*x_{i-1}+b_x,a_y*x_{i-1}+b_y) (xi,yi)=(axxi1+bx,ayxi1+by),now give your init position ( x s , y x ) (x_s,y_x) (xs,yx),Then you can stay on the plane for up to t t t seconds. ask how much you can collect the points?
题解(zh):这种点呈现线性关系,那么直接枚举点的起点和终点即可。
题解(en):This kind of point presents the linear relation, then you can directly enumerates beginning point and the end point.
c o d e : code: code:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
#define pll pair<ll,ll>
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=1e16;
const db eps=1e-9;
pll dots[500];
ll ax,ay,bx,by,xs,ys,t;
int main()
{
	scanf("%lld%lld%lld%lld%lld%lld%lld%lld%lld",&dots[0].fi,&dots[0].se,&ax,&ay,&bx,&by,&xs,&ys,&t);
	int tot;
	for(int i=1;;i++){
		ll nx=ax*dots[i-1].fi+bx,ny=ay*dots[i-1].se+by;
		dots[i]={nx,ny};
		if(nx>INF||ny>INF){tot=i;break;}
	}
	ll ans=0;
	for(int i=0;i<=tot;i++){
		ll tt=0;
		ll tmp=abs(xs-dots[i].fi)+abs(ys-dots[i].se);
		if(tmp<=t){
			tt=1;
			for(int j=0;j<=tot;j++){
				ll dis=abs(dots[i].fi-dots[j].fi)+abs(dots[i].se-dots[j].se);
				if(tmp+dis<=t){
					tt+=abs(i-j);
					ans=max(ans,tt);
					tt=1;
				}
			}
		}
	}
	printf("%lld\n",ans);
    return 0;
}

E. Xenon’s Attack on the Gangs

题目:传送门
大意(zh):给出了一个树,树中所有边的权值未定,需要你来自己定,两个约束:一、所有边的边权只能是 0 ∼ n − 2 0\sim n-2 0n2,二、所有边的边权各不相同,最后在这个树上求一个 s s s值,并且你确定这个 s s s值最大是多少?
s = ∑ 1 ≤ u < v ≤ n m e x ( u , v ) s=\sum_{1\le u < v \le n}mex(u,v) s=1u<vnmex(u,v)
大意(en):Now give you a tree, the weights of all the edges in the tree are not determined, it’s up to you, now you be constrained by two conditions: firstly, the weights of all the edges in the tree are supposed to between 0 0 0 and n − 2 n-2 n2, secondly, each edges of the tree should be indistinct. Finally you’ll to calculate a value on this tree, ans you determine what the maximum value of this s s s value is.
题解(zh):部分参考b站知名up,对于这个 m e x mex mex,需要进行贡献转化,例如如下图
在这里插入图片描述
可以看到 0 0 0这条边左边 3 3 3个点,右边 2 2 2个点,那么 1 1 1贡献的值就是 3 ∗ 2 3*2 32,我们可以看到有
1 − 3 1-3 13
4 − 1 − 3 4-1-3 413
2 − 1 − 3 2-1-3 213
1 − 3 − 5 1-3-5 135
4 − 1 − 3 − 5 4-1-3-5 4135
2 − 1 − 3 − 5 2-1-3-5 2135
也就是说跨过这条边的两边一边各锁定一个点,那么也就是有 3 ∗ 2 3*2 32种选择路径了。
接着考虑 0 和 1 0和1 01都有,考虑接下来的贡献,可以看到要想 0 , 1 0,1 0,1都有,那么 1 − 3 − 5 1-3-5 135得留下来,左边有 3 3 3个点,右边有 1 1 1个点,贡献就是 3 ∗ 1 3*1 31,接着依次考虑,那么总贡献就是 6 + 3 + 1 = 10 6+3+1=10 6+3+1=10
可以从中发现一个有趣的事情是贡献都发生在一条链上,那么就可以把这条链进行 d p dp dp d p [ x ] [ y ] dp[x][y] dp[x][y]表示从 x x x端点到 y y y端点是一条链的 s s s的最大值,那么状态转移方程为
d p [ x ] [ y ] = m a x ( d p [ x ] [ y ] , c n t [ y ] [ x ] ∗ c n t [ x ] [ y ] + m a x ( s o l v e ( f a [ y ] [ x ] , y ) , s o l v e ( x , f a [ x ] [ y ] ) ) ) dp[x][y]=max(dp[x][y],cnt[y][x]*cnt[x][y]+max(solve(fa[y][x],y),solve(x,fa[x][y]))) dp[x][y]=max(dp[x][y],cnt[y][x]cnt[x][y]+max(solve(fa[y][x],y),solve(x,fa[x][y])))
其中 c n t [ x ] [ y ] , f a [ x ] [ y ] cnt[x][y],fa[x][y] cnt[x][y],fa[x][y]表示是在 x x x为根节点的情况下, y y y的子树大小和 y y y的父节点是谁?
题解(en):有点复杂,就不再写了
c o d e : code: code:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=3e3+5;
int n,u,v,fa[N][N],cnt[N][N];
ll dp[N][N];
vector<int>E[N];
void add_edges(int x,int y){E[x].pb(y);E[y].pb(x);}
void dfs(int u,int root,int f)
{
	fa[root][u]=f;
	cnt[root][u]=1;
	rep(i,0,E[u].size()-1){
		int v=E[u][i];
		if(v==f)continue;
		dfs(v,root,u);
		cnt[root][u]+=cnt[root][v];
	}
}
ll solve(int x,int y)
{
	if(x==y)return 0;
	if(dp[x][y]!=-1)return dp[x][y];
	dp[x][y]=max(dp[x][y],cnt[y][x]*cnt[x][y]+max(solve(fa[y][x],y),solve(x,fa[x][y])));
	return dp[x][y];
}
int main()
{
    sc(n);
	rep(i,1,n-1){
		sc2(u,v);
		add_edges(u,v);
	}
	rep(i,1,n)dfs(i,i,-1);
	mm(dp,-1);
	ll ans=0;
	rep(i,1,n)rep(j,1,n)ans=max(ans,solve(i,j));
	printf("%lld\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于C++&OPENCV 的全景图像拼接 C++是一种广泛使用的编程语言,它是由Bjarne Stroustrup于1979年在新泽西州美利山贝尔实验室开始设计开发的。C++是C语言的扩展,旨在提供更强大的编程能力,包括面向对象编程和泛型编程的支持。C++支持数据封装、继承和多态等面向对象编程的特性和泛型编程的模板,以及丰富的标准库,提供了大量的数据结构和算法,极大地提高了开发效率。12 C++是一种静态类型的、编译式的、通用的、大小写敏感的编程语言,它综合了高级语言和低级语言的特点。C++的语法与C语言非常相似,但增加了许多面向对象编程的特性,如类、对象、封装、继承和多态等。这使得C++既保持了C语言的低级特性,如直接访问硬件的能力,又提供了高级语言的特性,如数据封装和代码重用。13 C++的应用领域非常广泛,包括但不限于教育、系统开发、游戏开发、嵌入式系统、工业和商业应用、科研和高性能计算等领域。在教育领域,C++因其结构化和面向对象的特性,常被选为计算机科学和工程专业的入门编程语言。在系统开发领域,C++因其高效性和灵活性,经常被作为开发语言。游戏开发领域中,C++由于其高效性和广泛应用,在开发高性能游戏和游戏引擎中扮演着重要角色。在嵌入式系统领域,C++的高效和灵活性使其成为理想选择。此外,C++还广泛应用于桌面应用、Web浏览器、操作系统、编译器、媒体应用程序、数据库引擎、医疗工程和机器人等领域。16 学习C++的关键是理解其核心概念和编程风格,而不是过于深入技术细节。C++支持多种编程风格,每种风格都能有效地保证运行时间效率和空间效率。因此,无论是初学者还是经验丰富的程序员,都可以通过C++来设计和实现新系统或维护旧系统。3

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值