当前位置:网站首页>7-2 芬兰木棋 结构体排序
7-2 芬兰木棋 结构体排序
2022-06-28 07:00:00 【wow_awsl_qwq】
7-2 芬兰木棋
分数 25
作者 DAI, Longao
单位 杭州百腾教育科技有限公司
WX20200212-152528.png
芬兰木棋(Mölkky,又称芬兰木柱)是源自芬兰的一项运动。哲哲将这个运动改造成了赛博朋克单人版,现在场上一开始有 N 根立起的小木棋(上面分别标有一个非负整数),哲哲投掷一根大木棋去击倒这些小木棋以获得分数。分数规则如下:
如果仅击倒 1 根木棋,则得木棋上的分数。
如果击倒 2 根或以上的木棋,则只得击倒根数的分数。(例如击倒 5 根,则得 5 分。)
哲哲固定站在 (0,0) 点上,四周放着若干个小木棋 (X
i
,Y
i
),坐标均为整数。每次哲哲可以朝一个方向扔出大木棋,大木棋会打倒这个方向上离哲哲最近的 k 个小木棋。哲哲游戏水平很高超,所以这个 k 可以自由控制。
请问哲哲最多能拿多少分,在获得最多分数的情况下最少需要扔出多少次大木棋?
规则与真实规则有较大出入,真实游玩时请以国际莫尔基组织的规则为准
输入格式:
输入第一行是一个正整数 N (1 ≤ N ≤ 10
5
),表示场上一开始有 N 个木棋。
接下来 N 行,每行 3 个整数 X
i
,Y
i
,P
i
,分别表示木棋放置在 (X
i
,Y
i
),木棋上的分数是 P
i
。坐标在 32 位整数范围内,分数为小于等于 1000 的正整数。
保证 (0,0) 点没有木棋,也没有木棋重叠放置。
输出格式:
输出一行两个数,表示最多分数以及获得最多分数最少需要投掷大木棋多少次。
输入样例:
11
1 2 2
2 4 3
3 6 4
-1 2 2
-2 4 3
-3 6 4
-1 -2 1
-2 -4 1
-3 -6 1
-4 -8 2
2 -1 999
输出样例:
1022 9
不会写:17分
猜测可以通过结构体排序,同一斜率的w=1的点总共算一次,但是遇到了不为1的点后,需要将标记重置
仅用map的话没办法按照顺序判断
#include<bits/stdc++.h>
using namespace std;
int ans,cnt;
map<double,bool> st1,st2;
bool x1,x2;
int main()
{
int n;cin>>n;
while(n--)
{
//int x,y;
double x,y;
int w;cin>>x>>y>>w;
if(w==1)
{
double k=y*1.0/x;
if(x)
if(y>0){
if(st1[k]==false){
st1[k]=true;
cnt++;
}
}else if(y==0){
if(x>0&&x1==false){
x1=true;
cnt++;
}
if(x<0&&x2==false){
x2=true;
cnt++;
}
}else {
if(st2[k]==false){
st2[k]=true;
cnt++;
}
}
}
else cnt++;
ans+=w;
}
cout<<ans<<" "<<cnt;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int ans,cnt;
map<double,bool> st1,st2;
int idx;
struct node
{
int x,y;
double k;
int t=0;
}ns[100005];
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
bool cmp(node a,node b)
{
if(a.t!=b.t)return a.t<b.t;
return a.k<b.k;
}
bool x1,x2;
int main()
{
int n;cin>>n;
while(n--)
{
int x,y;
//double x,y;
int w;cin>>x>>y>>w;
if(w==1)
{
double k=y*1.0/x;
int d=gcd(x,y);
x/=d;
y/=d;
if(y>0)
{
ns[idx].x=x;
ns[idx].y=y;
ns[idx].k=k;
ns[idx++].t=1;
}else if(y<0)
{
ns[idx].x=x;
ns[idx].y=y;
ns[idx++].k=k;
}else if(y==0)
{
if(x>0&&x1==false)
{
cnt++;
x1=true;
}
else if(x<0&&x2==false)
{
cnt++;
x2=true;
}
}
}
else cnt++;
ans+=w;
}
for(int i=0;i<idx;++i)
{
if(i==0){
cnt++;
continue;
}
if(ns[i-1].t==ns[i].t&&(ns[i-1].x!=ns[i].x||ns[i-1].y!=ns[i].y))
{
cnt++;
}else if(ns[i-1].t!=ns[i].t){
cnt++;
}
}
cout<<ans<<" "<<cnt;
return 0;
}
边栏推荐
- Integer promotion and size side byte order
- Recommend 10 popular jupyter notebook plug-ins to make you fly efficiently
- Freeswitch使用originate转dialplan
- Linked list (II) - Design linked list
- 【C语言】详解 C 语言获取数组长度
- [rust daily] published on rust 1.43.0 on April 23, 2020
- extern “C“概述
- 文件头信息对照表
- Causes of wechat applet compilation page blank bug
- Comment la passerelle BACnet / IP recueille - t - elle les données du système central de contrôle des bâtiments?
猜你喜欢
Wechat applets - basics takes you to understand the life cycle of applets (I)
Linked list (III) - reverse linked list
FPGA - 7系列 FPGA SelectIO -07- 高级逻辑资源之ISERDESE2
[online tutorial] official iptables tutorial -- learning notes 1
FPGA - 7系列 FPGA SelectIO -09- 高级逻辑资源之IO_FIFO
什么是一致性哈希?可以应用在哪些场景?
Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner
Comment la passerelle BACnet / IP recueille - t - elle les données du système central de contrôle des bâtiments?
选拔赛题目代码
编译配置in文件
随机推荐
Servlet value passing JSP
Call interface event API common event methods
RN7302三相电量检测(基于STM32单片机)
整型提昇和大小端字節序
Exception handling (I) -- null pointer and array index out of bounds
小小一款代码编辑器竟然也可以有程序运行之功能——Sublime Text3运行各种语言程序的总结
微信小程序编译页面空白bug的原因
Introduction to browser tools: think sky browser, team work browser
Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner
MySQL (II) - basic operation
语音增强-频谱映射
【C语言】详解 C 语言获取数组长度
FPGA - 7系列 FPGA SelectIO -08- 高级逻辑资源之OSERDESE2
Freeswitch uses origin to dialplan
[rust translation] implement rust asynchronous actuator from scratch
freeswitch设置最大呼叫时长
Yesterday, I went to a large factory for an interview and asked me to do four arithmetic operations. Fortunately, I am smart enough
什么是一致性哈希?可以应用在哪些场景?
"Jay bear" plummeted by 96.6%. Why is NFT with star goods cold?
微信小程序分页功能,下拉刷新功能,直接干货拿来就用