Game on Plane

题目链接

题意:Alice选择k条直线,Bob任意画一条直线,问Bob画的直线和Alice选择的直线最少有多少条相交?Alice的目标是使结果尽可能大,Bob反之

解析:贪心即可,Bob为了使结果尽可能小,显然会画尽可能多的与当前直线平行的直线,Alice则要使选择的直线中平行线尽可能少

AcCode:

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

#define pint std::pair<int,int>
#define pai std::pair<std::pair<int,int>,int>

std::map<pint, int> mp;
std::vector<pai> vec;

inline bool cmp(pai a, pai b) { return a.second > b.second; }

inline int gcd(int a, int b) { while (b) { int c = b; b = a % b; a = c; }return a; }

signed main() {
	int t; scanf("%d", &t);
	while (t--) {
		mp.clear();
		vec.clear();
		int n; scanf("%d", &n);
		for (int i = 1, a, b, c, d; i <= n; i++) {
			scanf("%d %d %d %d", &a, &b, &c, &d);
			int y = d - b, x = c - a;
			int g = gcd(x, y);
			x /= g, y /= g;
			if (x <= 0 && y <= 0) x = -x, y = -y;
			pint p = std::make_pair(x, y);
			mp[p]++;
		}
		int out = 0;
		for (auto& m : mp) {
			pai p = std::make_pair(m.first, m.second);
			vec.push_back(p);
		}
		sort(vec.begin(), vec.end(), cmp);
		while (!vec.empty()) {
			printf("%d\n", out);
			vec.front().second--;
			int sz = vec.size();
			for (int i = 1; i < sz; i++) {
				printf("%d\n", ++out);
				vec[i].second--;
			}
			while (!vec.empty() && vec.back().second == 0) vec.pop_back();
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
void Show_Extend() { //cleardevice(); Date_IMAGE_Init(); Play = { 400,350,169,52, BLACK,"简单模式" }; Introduce = { 400, 404, 169, 52, BLACK, "困难模式" }; Upgrade_of_Combat = { 400, 456, 169, 52,BLACK, "炼狱模式" }; while(1) { // 贴图 & 绘制按键 DrawAlpha_Transparent(&img_tmp_Extend, 0, 0, &img_Extend); DrawAlpha_Transparent(&img_tmp_Extend, Play.x, Play.y, &img_Extend_Button); DrawAlpha_Transparent(&img_tmp_Extend, Introduce.x, Introduce.y, &img_Extend_Button); DrawAlpha_Transparent(&img_tmp_Extend, Upgrade_of_Combat.x, Upgrade_of_Combat.y, &img_Extend_Button); DrawAlpha_Transparent(&img_tmp_Extend, 100, 0, &Plane_Game); putimage(0, 0, &img_tmp_Extend); DrawImage_BUTTON(&Play); DrawImage_BUTTON(&Upgrade_of_Combat); DrawImage_BUTTON(&Introduce); FlushBatchDraw(); // 按键判断 if (MouseHit()) { MOUSEMSG msg = GetMouseMsg(); if (Switch_Buton(&Play, msg.x, msg.y)) Play.color = RGB(234, 54, 128); else Play.color = BLACK; if (Switch_Buton(&Upgrade_of_Combat, msg.x, msg.y)) Upgrade_of_Combat.color = RGB(234, 54, 128); else Upgrade_of_Combat.color = BLACK; if (Switch_Buton(&Introduce, msg.x, msg.y)) Introduce.color = RGB(234, 54, 128); else Introduce.color = BLACK; switch (msg.uMsg) { case WM_LBUTTONDOWN: if (Switch_Buton(&Play, msg.x, msg.y)) // 简单模式 { enemya_num = 12; v_enemyb = 3; v_enemyc = 5; BOSS_Damage = 5; BOSS_num = 12; goto next; } if (Switch_Buton(&Upgrade_of_Combat, msg.x, msg.y)) // 困难模式 { enemya_num = 15; v_enemyb = 6; v_enemyc = 8; BOSS_Damage = 8; BOSS_num = 15; goto next; } if (Switch_Buton(&Introduce, msg.x, msg.y)) // 炼狱模式 { enemya_num = 20; v_enemyb = 9; v_enemyc = 10; BOSS_Damage = 15; BOSS_num = 20; goto next; } } } } next: Init_Button(); f[0] = 0; cleardevice(); }请为上述程序画出流程图
最新发布
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值