1265 - C. Beautiful Regional Contest (贪心)

本文针对一项编程竞赛题目提出了解决方案,通过将队伍按解题数量分组,并采用贪心算法来分配奖牌,确保了金牌数量最少且各类奖牌都能得到合理分配,同时满足奖牌总数不超过参赛队伍数一半的条件。

题目

思路:要求每个金牌切的题高于银牌,银牌高于铜牌,铜牌高于铁牌,那么必然对于切题一样的队伍只会获得相同的牌。此时我们把切题一样的队看作一个个打包好了的队伍堆,给牌必须一堆一堆的给。且要求金牌一定小于铜牌和银牌,最后要使给出的牌子最多,且给的牌子<=总数/2,每个牌子>0。那么先贪心一下,让金牌只取一个切题最高的堆(留下更多的堆,为了满足每种牌子都有的给,且有多余的堆就给铜和银,不会造成牌子浪费),然后再给银牌取到正好大于金牌,剩下的还能给牌子且使牌子总数<=n/2全给铜牌,如果最终答案银牌或铜牌少于金则不存在,细节见代码。

Code:

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
#define pii pair<int,int>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 2e6 + 5;
int lst[Max];

int main()
{
	int t;cin >> t;
	while (t--)
	{
		int n;cin >> n;
		map<int, int,greater<int>> ma;
		for (int i = 1;i <= n;i++)
		{
			cin >> lst[i];ma[lst[i]]++;
		}
		int s1 = ma[lst[1]], s2 = 0, s3 = 0;
		for (auto i = ma.begin();i != ma.end();i++)
		{
			if (ma.size() <= 3)break;
			if (i == ma.begin())i++;
			if(s2<=s1)s2 += i->second;
			else
			{
				if (s1+s2+s3 + i->second>n/2)break;
				s3 += i->second;
			}
		}
		if (s2 <= s1 || s3 <= s1)cout << "0 0 0" << endl;
		else cout << s1 << " " << s2 << " " << s3 << endl;
	}
}

那个左右滑动切换的问题,我正在排查,最终定位到是赛事赛题列表组件的问题(隐藏这个组件可以滑动),我怀疑是报错信息未解决导致划动不了,我查看浏览器报错:WebSocket connection to 'wss://localhost.chasiwu-sit.chaspark.cn:8087/?token=lBdndKpQW9Jz' failed: createConnection @ client:755 connect @ client:426 connect @ client:764 connect @ client:279 connect @ client:372 (anonymous) @ client:861Understand this errorAI client:768 WebSocket connection to 'wss://localhost:8087/?token=lBdndKpQW9Jz' failed: createConnection @ client:768 connect @ client:426 connect @ client:775Understand this errorAI client:783 [vite] failed to connect to websocket. your current setup: (browser) localhost.chasiwu-sit.chaspark.cn:8087/ <--[HTTP]--> localhost:8087/ (server) (browser) localhost.chasiwu-sit.chaspark.cn:8087/ <--[WebSocket (failing)]--> localhost:8087/ (server) Check out your Vite / network configuration and https://vite.dev/config/server-options.html#server-hmr . connect @ client:783 await in connect connect @ client:279 connect @ client:372 (anonymous) @ client:861Understand this errorAI chunk-FPEHBWIL.js?v=a329eec5:521 Warning: withRouter(CacheSwitch2): Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. at C2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:792:37) at DataProvider (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/Contexts/DataContext.js:7:3) at default (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/index.js?t=1764215092864:14:16) at Suspense at Switch2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:1131:33) at Router2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:875:34) at Provider (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-redux.js?v=a329eec5:918:3) at ConfigProvider (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/antd-mobile.js?v=a329eec5:489:5) at IntlProvider3 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-intl.js?v=a329eec5:4204:45) at AppH5 at Suspense printWarning @ chunk-FPEHBWIL.js?v=a329eec5:521 error @ chunk-FPEHBWIL.js?v=a329eec5:505 validateFunctionComponentInDev @ chunk-FPEHBWIL.js?v=a329eec5:15067 mountIndeterminateComponent @ chunk-FPEHBWIL.js?v=a329eec5:15036 beginWork @ chunk-FPEHBWIL.js?v=a329eec5:15962 beginWork$1 @ chunk-FPEHBWIL.js?v=a329eec5:19806 performUnitOfWork @ chunk-FPEHBWIL.js?v=a329eec5:19251 workLoopConcurrent @ chunk-FPEHBWIL.js?v=a329eec5:19242 renderRootConcurrent @ chunk-FPEHBWIL.js?v=a329eec5:19217 performConcurrentWorkOnRoot @ chunk-FPEHBWIL.js?v=a329eec5:18728 workLoop @ chunk-FPEHBWIL.js?v=a329eec5:197 flushWork @ chunk-FPEHBWIL.js?v=a329eec5:176 performWorkUntilDeadline @ chunk-FPEHBWIL.js?v=a329eec5:384Understand this errorAI chunk-CZS4DZFE.js?v=a329eec5:183 Warning: [antd: Dropdown] `onVisibleChange` is deprecated which will be removed in next major version, please use `onOpenChange` instead. warning @ chunk-CZS4DZFE.js?v=a329eec5:183 call @ chunk-CZS4DZFE.js?v=a329eec5:202 warningOnce @ chunk-CZS4DZFE.js?v=a329eec5:207 warning4 @ antd.js?v=a329eec5:1070 (anonymous) @ antd.js?v=a329eec5:16296 Dropdown3 @ antd.js?v=a329eec5:16294 renderWithHooks @ chunk-FPEHBWIL.js?v=a329eec5:11596 mountIndeterminateComponent @ chunk-FPEHBWIL.js?v=a329eec5:14974 beginWork @ chunk-FPEHBWIL.js?v=a329eec5:15962 beginWork$1 @ chunk-FPEHBWIL.js?v=a329eec5:19806 performUnitOfWork @ chunk-FPEHBWIL.js?v=a329eec5:19251 workLoopSync @ chunk-FPEHBWIL.js?v=a329eec5:19190 renderRootSync @ chunk-FPEHBWIL.js?v=a329eec5:19169 performConcurrentWorkOnRoot @ chunk-FPEHBWIL.js?v=a329eec5:18728 workLoop @ chunk-FPEHBWIL.js?v=a329eec5:197 flushWork @ chunk-FPEHBWIL.js?v=a329eec5:176 performWorkUntilDeadline @ chunk-FPEHBWIL.js?v=a329eec5:384Understand this errorAI chunk-CZS4DZFE.js?v=a329eec5:183 Warning: [antd: Dropdown] `overlay` is deprecated. Please use `menu` instead. warning @ chunk-CZS4DZFE.js?v=a329eec5:183 call @ chunk-CZS4DZFE.js?v=a329eec5:202 warningOnce @ chunk-CZS4DZFE.js?v=a329eec5:207 warning4 @ antd.js?v=a329eec5:1070 Dropdown3 @ antd.js?v=a329eec5:16298 renderWithHooks @ chunk-FPEHBWIL.js?v=a329eec5:11596 mountIndeterminateComponent @ chunk-FPEHBWIL.js?v=a329eec5:14974 beginWork @ chunk-FPEHBWIL.js?v=a329eec5:15962 beginWork$1 @ chunk-FPEHBWIL.js?v=a329eec5:19806 performUnitOfWork @ chunk-FPEHBWIL.js?v=a329eec5:19251 workLoopSync @ chunk-FPEHBWIL.js?v=a329eec5:19190 renderRootSync @ chunk-FPEHBWIL.js?v=a329eec5:19169 performConcurrentWorkOnRoot @ chunk-FPEHBWIL.js?v=a329eec5:18728 workLoop @ chunk-FPEHBWIL.js?v=a329eec5:197 flushWork @ chunk-FPEHBWIL.js?v=a329eec5:176 performWorkUntilDeadline @ chunk-FPEHBWIL.js?v=a329eec5:384Understand this errorAI index.js:213 Warning: Each child in a list should have a unique "key" prop. Check the render method of `BetaSlots`. See https://reactjs.org/link/warning-keys for more information. at SpotItem (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/components/FilterList/modules/SportingEventItem/index.js?t=1764145480809:13:5) at BetaSlots (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/contest/home/modules/BetaSlots/index.js?t=1764148443052:47:5) at div at div at div at https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/antd-mobile.js?v=a329eec5:1859:50 at PullToRefresh (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/antd-mobile.js?v=a329eec5:16309:7) at div at Content (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/home/modules/Content/index.js?t=1764145480809:14:5) at div at window.$RefreshReg$ (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/home/modules/Layouts/index.js?t=1764214325461:19:20) at default (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/contest/home/index.js?t=1764214325461:17:41) at div at Suspense at Layouts (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/components/Layouts/index.js?t=1764215092864:71:5) at https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/loader.js?t=1764215092864:15:22 at Updatable2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:885:9) at Suspender2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:792:9) at Suspense at Freeze (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:824:26) at DelayFreeze2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:844:9) at Updatable$1 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:904:26) at div at CacheComponent2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:587:9) at Route2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:1017:33) at CacheRoute2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:917:9) at https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:1046:31 at Updatable2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:885:9) at Suspender2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:792:9) at Suspense at Freeze (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:824:26) at DelayFreeze2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:844:9) at Updatable$1 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:904:26) at CacheSwitch2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-router-cache-route.js?v=a329eec5:1077:9) at C2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:792:37) at DataProvider (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/Contexts/DataContext.js:7:3) at default (https://localhost.chasiwu-sit.chaspark.cn:8087/src/h5/routes/index.js?t=1764215092864:14:16) at Suspense at Switch2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:1131:33) at Router2 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/chunk-R4H6Z5XC.js?v=a329eec5:875:34) at Provider (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-redux.js?v=a329eec5:918:3) at ConfigProvider (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/antd-mobile.js?v=a329eec5:489:5) at IntlProvider3 (https://localhost.chasiwu-sit.chaspark.cn:8087/node_modules/.vite/deps/react-intl.js?v=a329eec5:4204:45) at AppH5 at Suspense printWarning @ react_jsx-dev-runtime.js?v=a329eec5:64 error @ react_jsx-dev-runtime.js?v=a329eec5:48 validateExplicitKey @ react_jsx-dev-runtime.js?v=a329eec5:724 validateChildKeys @ react_jsx-dev-runtime.js?v=a329eec5:737 jsxWithValidation @ react_jsx-dev-runtime.js?v=a329eec5:855 BetaSlots @ index.js:213 renderWithHooks @ chunk-FPEHBWIL.js?v=a329eec5:11596 updateFunctionComponent @ chunk-FPEHBWIL.js?v=a329eec5:14630 beginWork @ chunk-FPEHBWIL.js?v=a329eec5:15972 beginWork$1 @ chunk-FPEHBWIL.js?v=a329eec5:19806 performUnitOfWork @ chunk-FPEHBWIL.js?v=a329eec5:19251 workLoopSync @ chunk-FPEHBWIL.js?v=a329eec5:19190 renderRootSync @ chunk-FPEHBWIL.js?v=a329eec5:19169 performConcurrentWorkOnRoot @ chunk-FPEHBWIL.js?v=a329eec5:18728 workLoop @ chunk-FPEHBWIL.js?v=a329eec5:197 flushWork @ chunk-FPEHBWIL.js?v=a329eec5:176 performWorkUntilDeadline @ chunk-FPEHBWIL.js?v=a329eec5:384Understand this errorAI :8087/#/races:1 Access to fetch at 'https://gray.chaspark.net/chasiwu/media/v1/tinyimage/1140494973038608384.jpg?_t=1764224204789&lang=zh' from origin 'https://localhost.chasiwu-sit.chaspark.cn:8087' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.Understand this errorAI gray.chaspark.net/chasiwu/media/v1/tinyimage/1140494973038608384.jpg?_t=1764224204789&lang=zh:1 GET https://gray.chaspark.net/chasiwu/media/v1/tinyimage/1140494973038608384.jpg?_t=1764224204789&lang=zh net::ERR_FAILED Promise.then (anonymous) @ chunk-VSIV6B2H.js?v=a329eec5:89 execute @ chunk-VSIV6B2H.js?v=a329eec5:87 send @ fetch.js:178 (anonymous) @ fetch.js:204 img.onload @ utils.js:137Understand this errorAI utils.js:123 Uncaught (in promise) TypeError: Failed to fetch Promise.then (anonymous) @ chunk-VSIV6B2H.js?v=a329eec5:89 execute @ chunk-VSIV6B2H.js?v=a329eec5:87 send @ fetch.js:178 (anonymous) @ fetch.js:204 img.onload @ utils.js:137Understand this errorAI 你看看是否有
最新发布
11-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_Rikka_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值