7-2芬兰木棋

这篇博客介绍了一个C++程序,它处理输入的坐标(x, y)和类型信息,通过typefunction函数判断象限,并进行坐标约简。程序使用map存储并排序数据,计算结果。主要涉及算法、数据结构和C++编程。
摘要由CSDN通过智能技术生成

这是我之前写的一篇博客
https://blog.nowcoder.net/n/f9141f797de94001b5507265ae6f2aa3
下面附上正确代码

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; 
typedef pair< int,pair<int ,int > > judge;
map< judge,vector<pair <LL , int> > > array1;
int N;
LL res=0;
int ans=0;

int typefunction(int x,int y){
    if(x>0&&y>=0) return 0;
	if(x<=0&&y>0) return 1;
	if(x<0&&y<=0) return 2;
	if(x>=0&&y<0) return 3;
}
void kfunction(LL &m,LL &n){ ///化成最小的约数 
	LL m0 = m, n0 = n;    //m0和n0保存m和n的原始值
	while (m%n != 0) {
		LL temp = m ;
		m = n;
		n = temp%n;
	}
	m=m0/n;
	n=n0/n;
	return ;
}
int main(){
   scanf("%d",&N);
   for(int i=0;i<N;++i)
   {
   	    LL x,y ;int p;
   	    scanf("%lld%lld%d",&x,&y,&p);
   	    res+=p;
		       int index=typefunction(x,y);
		       x=abs(x),y=abs(y);
		       if(x==0){
		       	pair<int,int> num1(0,1);
		       	judge NUM(index,num1);
		       	array1[NUM].push_back({y,p}); 
			   }
			   else if(y==0){
			   	pair<int,int> num1(1,0);
		       	judge NUM(index,num1);
		       	array1[NUM].push_back({x,p}); 
			   }
		       else{
		       	LL d=x*x+y*y;
		       	kfunction(x,y);
		       	pair<int,int> num1(x,y);
		       	judge NUM(index,num1);
		       	array1[NUM].push_back({d,p}); 
			   }
	}
	for(auto x : array1){
		vector<pair<LL, int>> vec = x.second;
		sort(vec.begin(),vec.end());
		for(int i=0;i<vec.size();++i){
			if(vec[i].second!=1){
				ans++;
			}
		    else if((vec[i+1].second!=1&&vec.size()>i+1)||i+1==vec.size()){
		    	ans++;
			}
		}
	}
	printf("%d %d",res,ans);    
	return 0;   	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值