当前位置:   article > 正文

7-2芬兰木棋_7-2 芬兰木棋

7-2 芬兰木棋

这是我之前写的一篇博客
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;   	
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号