/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:22:10: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if(k1<0&&k2>0||k1>0&&k2<0)
      ~~~~^~~~~~
/in/foo.cc:24:10: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if(c1<0&&c2>0||c1>0&&c2<0)
      ~~~~^~~~~~
# 状态 耗时 内存占用
#1 Accepted 4ms 264.0 KiB
#2 Accepted 4ms 352.0 KiB
#3 Accepted 4ms 372.0 KiB
#4 Accepted 3ms 356.0 KiB
#5 Accepted 5ms 256.0 KiB
#6 Accepted 4ms 364.0 KiB
#7 Accepted 3ms 364.0 KiB
#8 Accepted 3ms 384.0 KiB
#9 Accepted 4ms 348.0 KiB
#10 Accepted 3ms 364.0 KiB
#11 Accepted 3ms 376.0 KiB
#12 Accepted 3ms 336.0 KiB
#13 Accepted 3ms 352.0 KiB
#14 Accepted 3ms 356.0 KiB
#15 Accepted 4ms 256.0 KiB
#16 Accepted 3ms 384.0 KiB
#17 Accepted 3ms 384.0 KiB
#18 Accepted 4ms 264.0 KiB
#19 Accepted 3ms 376.0 KiB

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a1,b1,a2,b2;
inline ll gcd(ll x,ll y)
{
   	if(y==0) return x;
    else return gcd(y,x%y); 
}
int main()
{
	while(cin>>a1>>b1>>a2>>b2)
	{
		if(a1==a2||b1==b2)
		{
			cout<<"Error"<<endl;
			continue;
		}
		ll k1=b2-b1,k2=a2-a1;
		ll c1=b1*a2-a1*b2,c2=a2-a1;
		ll fk=0,fc=0,gk,gc;
		if(k1<0&&k2>0||k1>0&&k2<0)
			fk=1;
		if(c1<0&&c2>0||c1>0&&c2<0)
			fc=1;
		k1=abs(k1),k2=abs(k2);
		c1=abs(c1),c2=abs(c2);
		if(k1>k2) gk=gcd(k1,k2);
		else gk=gcd(k2,k1);
		if(c1>c2) gc=gcd(c1,c2);
		else gc=gcd(c2,c1);
		k1/=gk,k2/=gk;
		c1/=gc,c2/=gc;
		cout<<"y=";
		if(fk) cout<<"-";
		if((k1==1&&k2!=1)||(k1!=1)) cout<<k1;
		if(k2!=1) cout<<"/"<<k2;
		cout<<"x";
		if(c1==0) cout<<endl;
		else
		{
			if(fc) cout<<"-";
			else cout<<"+";
			cout<<c1;
			if(c2!=1) cout<<"/"<<c2;
			cout<<endl;
		}
	}
}

信息

递交者
类型
递交
题目
数学弱智题 T3
题目数据
下载
语言
C++
递交时间
2017-11-03 09:48:11
评测时间
2017-11-03 09:48:11
评测机
分数
100
总耗时
75ms
峰值内存
384.0 KiB