Educational Codeforces Round 131 (Rated for Div. 2)


一、A - Grass Field

  • 题目:
    给你两行两列的表格,表格只有1和0,每次可以删除一行和一列的1,问你最少几次使得表格里面没有1
  • 思路:
    观察到当表格中1的个数 <=3时只用一次就行,(如果1的个数是0个的话,就是0次),否则如果表格中的1个个数是4个的话就是2次
  • 代码:
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb push_back
#define PII pair<int,int>
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long 
using namespace std;
const int N = 2e5 + 100,M = N * 2,mod = 1e9 + 7,INF = 0x3f3f3f3f;

void solve()
{
	int a,b,c,d,e = 0;
	cin >> a >> b >> c >> d;
	if(a == 1) e++;
	if(b == 1) e++;
	if(c == 1) e++;
	if(d == 1) e++;
	
	if(e == 0) cout << "0" << endl;
	else if(e <= 3) cout << "1" << endl;
	else  cout << "2" << endl;
}

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

    return 0;
}

二、B - Permutation

  • 题目:
    你可以选择一个k,和一个排列来使得这个排列中 A[i] * k = A[i + 1]的个数尽量多,输出k和这个排列
  • 思路:
    明确k的取值,贪心发现k越小越好,越小可能的取值就越多,k不能取1,取1就一个也没有,那就取2就好,然后从小到大枚举每一个数字就行
  • 代码:
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb push_back
#define PII pair<int,int>
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long 
using namespace std;
const int N = 2e5 + 100,M = N * 2,mod = 1e9 + 7,INF = 0x3f3f3f3f;
bool st[N];
void solve()
{
	int n; cin >> n;
	cout << "2" << endl;
	memset(st,0,sizeof st);
	
	for(int i = 1;i <= n;i ++ )
	{
		if(!st[i])
		{
			cout << i << ' ';
			st[i] = true;
				for(int j = i * 2;j <= n;j = j * 2)
		{
			if(!st[j])
			{
				st[j] = true;
				cout << j << ' ';
			}
		}
		
		}
		
	
	}
	
	
	
	cout << endl;
}

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

    return 0;
}

三、C - Schedule Management

  • 题目:
    有n个人,m个任务,然后每个任务由特定的人来做是花费一个小时,否则花费两个小时,然后给你一个长度是m的数组,数组中的值A[i]是这个任务指定的特定的人,问你最少多长时间能把任务做完
  • 思路:
    统计每个人做的任务的个数B[i],然后考虑二分时间,如果当前二分的时间mid,满足条件的话,就缩小,否则放大,条件内容:如果当前的这个人做的任务个数是 <= mid,那这个人在剩余的时间里面可以帮助其他 人完成的任务个数是(mid - B[ i ]) / 2,用一个变量cnt 来统计这个个数,否则这个人目前的剩余任务是B[i] - mid,然后判断cnt是否大于B[i] - mid,大于代表别人可以帮成功,否则的话就失败
  • 代码:
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb push_back
#define PII pair<int,int>
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long 
using namespace std;
const int N = 2e5 + 100,M = N * 2,mod = 1e9 + 7,INF = 0x3f3f3f3f;
int a[N],b[N];
int n,m; 
bool check(int mid)
{
	int cnt = 0;
	for(int i = 1;i <= n;i ++ )
	{
		if(b[i] - mid <= 0) 
		{
			cnt += (mid - b[i]) / 2;
		}
		else
		{
			int u = b[i];
			u -= mid;
			if(cnt >= u)
			{
				cnt -= u;
			}
			else
			{
				return false;
			}
		}
	}
	
	return true;
}

void solve()
{
	cin >> n >> m;
	
	for(int i = 1;i <= m;i ++ ) cin >> a[i],b[a[i]]++;
	
	sort(b + 1,b + 1 + n);
	int l = 1,r = b[n]; 
	
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(mid)) r = mid - 1;
		else l = mid + 1; 
	}
	
	cout << l << endl;
	
	for(int i = 1;i <= n;i ++ ) b[i] = 0;
}

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

    return 0;
}

四、补:D - Permutation Restoration

  • 题目:
    B[i] = i / A[i],给你B,让你求A,都是排列
  • 思路:
    B[i] <= i / A[i] < B[i] + 1 ,转换一下就有 i / ( B[i] + 1 ) + 1<= A[i] <= i / B[i],左端点 L= i / ( B[i] + 1 ) + 1,右端点R = i / B[i], 注意如果B[i] = 0,R就是n,然后从左到右枚举左端点,然后找右端点最小的那一个就行,满足的是贪心思想,右边越短留给后面的选择就越多, 详细可阅这个连接
  • 代码:
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb push_back
#define PII pair<int,int>
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long 
using namespace std;
const int N = 5e5 + 100,M = N * 2,mod = 1e9 + 7,INF = 0x3f3f3f3f;
int a[N],b[N];
int n,m; 
vector<PII> res[N];
priority_queue<PII,vector<PII>,greater<PII> > q;
void solve()
{
	cin >> n; 
	for(int i = 1; i <= n;i ++ ) cin >> b[i];
	
	for(int i = 1;i <= n;i ++ )
	{
		int L = i / (b[i] + 1) + 1;
		int R = (b[i] == 0) ? n : i / b[i];
		res[L].pb({R,i});
	} 
	
	for(int i = 1;i <= n;i ++ )
	{
		for(PII p : res[i]) q.push(p);
		PII t = q.top();q.pop();
		a[t.se] = i;
	}
	
	for(int i = 1;i <= n;i ++ )
	{
		cout << a[i] << ' ';
		res[i].clear();
	}	
	
	cout << endl;
	
}

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

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值