7月2号写代码

先给题目连接
#include<bits/stdc++.h>
using namespace std;
typedef pair< int,pair<int ,int > > judge;
set< judge > array1;
int N;
long long 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(int &m,int &n){
	int m0 = m, n0 = n;    //m0和n0保存m和n的原始值
	while (m%n != 0) {
		int 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)
   {
   	    int x,y,p;
   	    scanf("%d%d%d",&x,&y,&p);
   	    res+=p;
		if(p==1){///计算 
		       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.insert(NUM);
			   }
			   else if(y==0){
			   	pair<int,int> num1(1,0);
		       	judge NUM(index,num1);
		       	array1.insert(NUM);
			   }
		       else{
		       	kfunction(x,y);
		       	pair<int,int> num1(x,y);
		       	judge NUM(index,num1);
		       	array1.insert(NUM);
			   }	       
		}else if(p>1){
			ans++;
		}    
	}
	ans+=array1.size();
	printf("%lld %d",res,ans);    
	return 0;   	
}
结果只有17分
我仔细读了一下题目
意思就是说
如果这个方向上有不是1的在中间
那就分开记
停下来单独打啊
这样的话就发现自己程序问题的所在了
程序预期输出5 3 结果实际输出5 2。
我们只要每有一个非一点在斜线上前后都有一点结果都加一
我将set数组改成了map存储后用c++11特有的for auto完成了程序
下面附上代码
#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 收藏 评论
分享
牛客网
牛客企业服务