首页 > 其他分享 >The 2024 ICPC Asia EC Regionals Online Contest (II)

The 2024 ICPC Asia EC Regionals Online Contest (II)

时间:2024-09-24 15:02:51浏览次数:1  
标签:cnt return Contest int EC II ++ long mod



A - Gambling on Choosing Regionals

题意

\(k\)场比赛,每场比赛每个大学至多\(c_i\)个队;总\(n\)个队伍,每队有分数与所属大学两个属性,每只队伍至多参加\(2\)场比赛。求各个队在最坏情况下的最优排名。

思路

最坏情况就是你打哪场,强队都去哪场,就选\(c_i\)小的场次,能让排名更靠前。对于每队能打两场,最坏情况,两场强队都跟着你,故考虑一场即可。

代码

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long

struct group
{
	int id, sc;
	string ut;
	bool operator < (const group a)
	{
		return sc > a.sc;
	}
};

void solve()
{
	int n, k, minn = LLONG_MAX;
	cin >> n >> k;
	for (int i = 0; i < k; i++)
	{
		int x;
		cin >> x;
		minn = min(minn, x); // 人最少的场次
	}
	vector<group> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i].sc >> v[i].ut;
		v[i].id = i;
	}
	sort(v.begin(), v.end()); // 按分数降序排
	map<string, int> cnt; 
	vector<int> ans(n);
	int cur = 0;
	for (int i = 0; i < n; i++)
	{
		if (cnt[v[i].ut] < minn) // v[i]所属大学的名额还有
		{
			cur++;
			cnt[v[i].ut]++;
		}
		ans[v[i].id] = cur;
	}
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int T = 1;
	//cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}



F - Tourist

题意

初始值\(1500\),给\(n\)个数,相加后问能否\(\ge 4000\),能则输出在第几次恰好\(\ge 4000\),否则输出-\(1\)。

思路

模拟。

代码

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve()
{
	int n, sum = 1500;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		sum += x;
		if (sum >= 4000)
		{
			cout << i + 1 << endl;
			return;
		}
	}
	cout << -1 << endl;
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int T = 1;
	//cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}


G - Game

题意

\(A\)与\(B\)玩游戏,最初各有\(x\)。\(y\)的筹码,各自赢的概率为\(p_0\)、\(p_1\),平局概率为\(1-p_0-p_1\)。平局时立刻进行下一局;当赢家的筹码\(\ge\)输家的,游戏结束,此时的赢家获胜;每局的输家要失去赢家此时的筹码数。问\(A\)最后获胜的概率。

思路

其实只用考虑3种情况:\(x = y\)、\(x < y\)、\(x > y\),然后递归,加上辗转相除递归次数不会很多。除法用逆元处理。

代码

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int mod = 998244353;

int x, y, a, b, c, p0, p1, p2;

int qpow(int base, int x) // 快速幂
{
	int res = 1;
	while (x)
	{
		if (x & 1)
		{
			res *= base;
			res %= mod;
		}
		x >>= 1;
		base *= base;
		base %= mod;
	}
	return res;
}

int dfs(int x, int y)
{
	if (x == y) // 筹码一样输了就死
	{
		return p0;
	}
	if (x < y) // 筹码少,只能一直赢
	{
		int cnt = y / x;
		if (y % x == 0)
		{
			cnt--; // 留一次判最后的 x == y
		}
		return (dfs(x, y - x * cnt) * (qpow(p0, cnt) % mod)) % mod;
	}
	int cnt = x / y;
	if (x % y == 0)
	{
		cnt--; 
	}
	return ((dfs(x - y * cnt, y) - 1 + mod) % mod * qpow(p1, cnt) % mod + 1) % mod;

}

void solve()
{
	cin >> x >> y >> a >> b >> c; // 赢的概率是 a / c 和 b / c
	c = a + b; // 除去平局
	// 逆元
	p0 = a * qpow(c, mod - 2) % mod; // A赢
	p1 = b * qpow(c, mod - 2) % mod; // B赢

	cout << dfs(x, y) << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}



I - Strange Binary

题意

给定非负整数\(n\),问是否能构造出序列\(A\)使得\(\sum_{i=0}^{31}2^i*a_i = n\),其中\(a_i\)满足:\(a_i = 1或0或 -1,a_i^2+a_{i+1}^2 \neq 0\)。有则输出任意满足要求的序列,否则输出\(NO\)。

思路

对于\(a_i\),它代表的就是第\(i\)位上的\(1\)(\([0,31]\)位每一位上只有1个\(1\)),所以\(a_{31}\)必定是\(1\),否则结果就一定是负数。而显然\(0, 0, 0, 1, 1\)等价于\(1,-1,-1,-1,1\)所以每个\(01\)结构都能这样凑出来,即对于第\(i\)位的\(1\),可以转化成\(2^i = 2^{i+1} - 2^i\),此时\(a_{i+1}=1,a_i = -1\),这时又可以将第\(i+1\)位上的\(0\)抵消。构造过程中发现,\(4\)的倍数(末尾有两个以上连续的\(0\)),或者中间有两个以上连续的\(0\),不能构造。

代码

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve()
{
	int n;
	cin >> n;
	vector<int> a(32);
	int idx = 0;
	while (n)
	{
		if (n & 1)
		{
			a[idx++] = 1;
		}
		else
		{
			a[idx++] = 0;
		}
		n >>= 1;
	}
	for (int i = 0; i <= 30; i++)
	{
		if (a[i] == 1 && a[i + 1] == 0) // 0,1可以凑成1,-1
		{
			a[i + 1] = 1;
			a[i] = -1;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (a[i] == 0 && a[i + 1] == 0) // 非法
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
	for (int i = 0; i <= 31; i++)
	{
		cout << a[i] << ((i + 1) % 8 ? " " : "\n");
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}

J - Stacking of Goods

题意

\(n\)个物品,每个物品有重量\(w\)、体积\(v\)和可压缩度\(c\)三种属性。你要讲物品堆叠,一个物品在堆叠后的体积是\(v_i-c_i*W\),其中\(W\)是其上方所有物品的重量之和。求所有物品堆叠后总体积的最小值。

思路

代码

点击查看代码


L - 502 Bad Gateway

题意

思路

代码

点击查看代码



比赛链接 https://codeforces.com/gym/105358

标签:cnt,return,Contest,int,EC,II,++,long,mod
From: https://www.cnblogs.com/Seii/p/18426548

相关文章

  • 华为全联接大会HUAWEI Connect 2024印象(五):讯飞星火企业级智能体平台
    在HC大会上,除了有华为自己的产品,还有很多合作伙伴的产品,今天就简单说一下讯飞星火的企业级智能体平台。讯飞星火此次在HC上有多个展台。我以前是讯飞星火的拥泵,在B站发过视频介绍其API的使用(利用API访问讯飞星火认知大模型平台_哔哩哔哩_bilibili)。在飞凌嵌入式的测评中,也使用......
  • 需求分析方法(场景五要素&5W3H&Y模型&MECE法则&人性七宗罪)
    一:业务需求和产品需求产品需求是对用户真实需求的提炼,形成产品需求后,要制定复合产品定位的解决方案,进而满足业务上的需求。需求分析就是将用户的需求(目的、想法、问题等)转为对应的产品解决方案(产品结构+产品流程+产品功能)。1.1需求的辨别需求真实:不是所有需求都是用户需要的。需......
  • 跑lvs出现soft connect怎么处理?
      首先,我们先了解一下什么是softconnect。简而言之,就是工具会将所有连接在psub上的信号认作softconnect(也就是short)。如图1所示,VSS和AVSS都接到了p+上,它们通过psub便有了softconnect。    如果有softconnect的话,lvs是没法pass的,会发现很多一堆stdcell连接了错......
  • 关于UndeclaredThrowableException异常
    说明动态代理里面抛出sentinel的异常发现抛出的是UndeclaredThrowableException包装了一层导致专门处理流控异常的地方不能正常处理  异常类图jdk动态原理对异常的处理生成的字节码参考https://www.cnblogs.com/LQBlog/p/16397103.htmlpublicfinalvoidsayHello(S......
  • DragDrop.DoDragDrop(DependencyObject, Object, DragDropEffects) 方法——控件拖动
    参数dragSourceDependencyObject对依赖项对象的引用(该对象是被拖动数据的源)。dataObject包含被拖动数据的数据对象。allowedEffectsDragDropEffectsDragDropEffects 值中的一个,指定拖放操作的允许效果。返回DragDropEffectsDragDropEffects 值中的一个,指定在拖......
  • hive报错Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.Ma
    问题:查看hive日志进入日志文件下查看hiveserver2.log我的hive日志在如下文件夹下:cd/var/log/my_hive_log如果日志中显示如下错误:Maximumwassetto100partitionspernode,numberofdynamicpartitionsonthisnode:101这个错误信息表明在某个节点上动态生成......
  • 万象更新 Html5 - es6 进阶: proxy, reflect
    源码https://github.com/webabcd/Html5作者webabcd万象更新Html5-es6进阶:proxy,reflect示例如下:es6\src\advanced\proxy_reflect.js//Proxy-代理(拦截目标对象的属性操作和函数操作)lettarget={name:'webabcd',age:40,gethello(){......
  • ExecutorService
    当你想要创建线程来执行任务的时候, 如果你newThread()来创建的话,就太low了,第一 频繁的newThread会大量消耗系统性能,第二大量重复创建线程会导致线程太多导致系统OOM第三 相比ExecutorService来说thread少了很多线程操作executorService用来创建线程池, 线程池有......
  • echarts两饼图连接映射
    最近开发中,突然来了一个echarts还要很快开发出来。。要老命了,遭老罪了。。先看需求图思考了半天还是有点思路,前端画图不就是搭积木嘛。1.中间蓝色阴影部分用canvas来做2.获取容器和饼图在页面上的位置,绘制梯形3.使用2个mask作为饼图圆心,用于遮挡echarts中心位置的梯......
  • 万象更新 Html5 - css: selector 选择器: 基础,通配符选择器,元素选择器,id 选择器,类选择
    源码https://github.com/webabcd/Html5作者webabcd万象更新Html5-css:selector选择器:基础,通配符选择器,元素选择器,id选择器,类选择器示例如下:css\src\selector\demo1.html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8">......