当前位置:   article > 正文

Educational Codeforces Round 100 (Rated for Div. 2) 虚拟参赛及补题。_codeforces虚拟赛加rate吗?

codeforces虚拟赛加rate吗?

A题,很简单吧。可以说是。

  • 思路
    9个一循环吧。
#include <bits/stdc++.h>

using namespace std;

const int N = 110;
typedef long long ll;
typedef pair<int, int> PII;


ll a[N];
int hsh[N];
int m;


void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	int res=a+b+c;
	if(res%9!=0)
	cout<<"NO"<<endl;
	else
	{
		int x=res/9;
		if(x<=a&&x<=b&&x<=c)
		cout<<"YES"<<endl;
		else
		{
			cout<<"NO"<<endl;
		}
	}

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

B题

  • 题意
    在这里插入图片描述

  • 思路
    偶数,放1,级数放a【i】;或者奇数放1,偶数放a【i】;
    因为这样奇数或者偶数,为0.偶数或者奇数的差会小于s/2;
    但是不一定哪一个小于s/2,所以要测试一下,是奇数放1还是偶数放1.
    两个两个的看,无非有一个会小于两者之和。

#include <bits/stdc++.h>

using namespace std;

const int N = 55;
typedef long long ll;
typedef pair<int, int> PII;

ll a[N];
int hsh[N];
int m;

ll b[N];
void solve()
{
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	ll s = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 2)
		{
			b[i] = 1;
			s +=(a[i]- b[i]);
		}
		else
		{
			b[i] = a[i];
			s += (a[i]-b[i]);
		}
	}
	
	if (s * 2 > sum)
	{
		for (int i = 1; i <= n; i++)
		{
			if (i % 2 == 0)
			{
				b[i] = 1;
			}
			else
			{
				b[i] = a[i];
			}
		}
	}
	for (int i = 1; i <= n; i++)
		cout << b[i] << " ";
	cout << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
D题
  • 题意
    在这里插入图片描述
  • 思路

在这里插入图片描述

  • 代码
#include <iostream>
#include <cstdio>

const int maxn=2e5+7;

using namespace std;

int T,n,sum,l,r;
int a[maxn];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		for (int i=1;i<=n;i++) scanf("%d",&a[i]);
		a[n+1]=2*n+1;
		l=0,r=0;
		sum=0;
		
		for (int i=1;i<=n;i++)
		{
			sum+=a[i]-a[i-1]-1;
			if (!sum) l++;
			     else sum--;
		}
		sum=0;
		for (int i=n;i>0;i--)
		{
			sum+=a[i+1]-a[i]-1;
			if (!sum) r++;
			     else sum--;
		}
		printf("%d\n",n-r-l+1);
	}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

C题

(模拟题)
题意
在这里插入图片描述

思路
在这里插入图片描述

代码

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
typedef long long ll;

ll T[N], X[N];

void solve()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> T[i] >> X[i];
	ll nowx = 0, end = 0;
	ll res = 0;
	T[n + 1] = 2e10;
	for (int i = 1; i <= n; i++)
	{
		if (nowx == end) end = X[i];
		ll l = nowx, r;
		if (nowx > end)
		{
			if (nowx - end >= T[i + 1] - T[i])
			{
				nowx -= T[i + 1] - T[i];
			}
			else
				nowx = end;
		}
		else
		{
			if (end - nowx >= T[i + 1] - T[i])
				nowx += T[i + 1] - T[i];
			else
				nowx = end;
		}
		r = nowx;
		if (l > r)
			swap(l, r);
		if (l <= X[i] && X[i] <= r)
			res++;
	}
	cout << res << endl;
}

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/55050
推荐阅读
相关标签
  

闽ICP备14008679号