Dashboard - Codeforces Round #802 (Div. 2)

题目链接

A

核心思路

观察样例就好了。

// Problem: A. Optimal Path
// Contest: Codeforces - Codeforces Round #802 (Div. 2)
// URL: https://codeforces.com/contest/1700/problem/A
// 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 


void solve()
{
	int n,m;
cin>>n>>m;

int sum=0;

for(int i=1;i<=m;i++)
sum+=i;
int t=m;
for(int i=1;i<=n-1;i++)
{
	t+=m;
	sum+=t;
}
 cout<<sum<<endl;
}


signed main()
{
	int u=0;
int T;
cin>>T;
while(T--)
{
	solve();
}
}

B

核心思路

这题的主要思路就是我们需要构造两组万能的解:分别是999 1111.这两个看情况使用就好了。

// Problem: B. Palindromic Numbers
// Contest: Codeforces - Codeforces Round #802 (Div. 2)
// URL: https://codeforces.com/contest/1700/problem/B
// 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 


void solve()
{
	int n;
	string a;
	cin>>n;
	cin>>a;
	
	string b,s;
	
	if(a[0]=='9')
	{
		s=string(n+1,'1');
		
	}
	else
	{
		s=string(n,'9');
	}
	reverse(a.begin(),a.end());
	int v=0;
	for(int i=0;i<n;i++)
	{
		int t=(int)(s[i]-a[i])-v;
		
		if(t<0)
		{
			t+=10;
			v=1;
		}
		
		else
		{
			v=0;
		}
		b+='0'+t;
	}
	reverse(b.begin(),b.end());
	
	cout<<b<<endl;
	
}

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

C

这题主要是对于区间的一些操作,所以我们需要想到进行差分转换。

我们可以将这三个操作转换为差分操作(c数组表示的是差分数组):

  • c[1]+=1,c[i+1]]-=1
  • c[i]-1
  • c[1]+1

我们如果要将原数组变为0,其实也就是将我们差分数组变为0.

因为题目需要我们最小化操作数,所以我们尽可能地使用操作1。如果遇到大于0地数就是用操作2,遇到小于0地就是操作1.最后就只有c[1]了,我们在使用整体操作就好了,也就是操作三和操作二都是可以的。

// Problem: C. Helping the Nature
// Contest: Codeforces - Codeforces Round #802 (Div. 2)
// URL: https://codeforces.com/contest/1700/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=1e6+10;

int a[N],b[N];

void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		b[i]=a[i]-a[i-1];
	}
	int sum=0;
	int sub=0;
	for(int i=2;i<=n;i++)//一定要注意这里是从2开始的。
	{
		sum+=abs(b[i]);
		if(b[i]<0)//这是为了统计对于使用操作1的同时对于a[1]有什么改变。
		{
			sub-=b[i];
		}
		
	}
	sum+=abs(b[1]-sub);
	
	cout<<sum<<endl;
	
}


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

D

核心思路

首先捋清楚题意吧,题目是给我们n个水库的容量并且刚开始都是空的。然后题目问的是我们需要把这些水库灌满最少需要打开多少个闸门,在时间t地限制之下。

首先考虑无解地情况,我们根据这个样例知道了把我们第一个水库灌满地时间是\(a[1]\),第二个是\((a[1]+a[2])/2\).一次类推。我们可以得出来把每一个水库灌满地值。然后取个最大值再去和t比较就知道了。

至于求答案这里很明显可以使用二分。

// Problem: D. River Locks
// Contest: Codeforces - Codeforces Round #802 (Div. 2)
// URL: https://codeforces.com/contest/1700/problem/D
// 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=1e6+10;

int a[N];

void solve()
{
	int n;
	cin>>n;
	int maxv=0,sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		sum+=a[i];
		maxv=max(maxv,(sum+i-1)/i);
		
	}
	int m;
	cin>>m;
	while(m--)
	{
		int t;
		cin>>t;
		if(maxv>t)
		{
			cout<<-1<<endl;
			continue;
		}
		int l=1,r=n;
		while(l<r)
		{
			int mid=l+r>>1;
			if(t*mid>=sum)
			r=mid;
			else
			l=mid+1;
		}
		
		
		cout<<r<<endl;
	}
	
	
	
}


signed main()
{
int T;
T=1;
while(T--)
{
	solve();
}
}
posted @ 2023-01-23 21:58  努力的德华  阅读(32)  评论(0)    收藏  举报