QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482877#3663. The Biggest TriangleYoussefproofWA 0ms3984kbC++202.5kb2024-07-17 23:25:022024-07-17 23:25:02

Judging History

你现在查看的是最新测评结果

  • [2024-07-17 23:25:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3984kb
  • [2024-07-17 23:25:02]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define float double
#define proof ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tests ll T;cin >> T;while(T--)
using namespace std;
const ll mod = 1e9 + 7;
struct line
{
    float slope,b;
    float xx ;
    line(float x1,float y1,float x2,float y2)
    {
        //NOT HANDELING X2 - X1 = 0
        if(x1==x2){
            slope = 1e7 + 10;
            xx = x1;
        }
        else
            slope = (y2 - y1) / (x2 - x1);
        b = y2 - slope*x2;
        if (x1==x2) b = 0;
    }
};
float eps =1e-5;
pair<float,float> getIntersection(line l1,line l2)
{
    float x,y;
    if(l1.slope-1e7-10 <= eps)
      swap(l1,l2);
    x = (l1.b - l2.b)/(l2.slope - l1.slope);
    
    if(l2.slope-1e7-10 <= eps)
    {
        x = l2.xx;
        y = l1.slope * x + l1.b;
    }
    else
        y = l2.slope*x + l2.b;
    return {x,y};
} 
float getdist(pair<float,float>p1,pair<float,float>p2)
{
    return sqrt(pow(p2.second - p1.second,2) + pow(p2.first - p1.first,2));
}
void solve()
{
    ll n;cin >> n;
    vector<line>v;
    for (int i = 0; i < n; i++)
    {
        float x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        v.push_back(line(x1,y1,x2,y2));
    }
    float ans,maxans = -1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i == j || v[i].slope == v[j].slope) continue;
            for (int k = 0; k < n; k++)
            {
                if (j == k || i == k || v[i].slope == v[k].slope || v[j].slope == v[k].slope) continue;
                pair<float,float>p1,p2,p3;
                p1 = getIntersection(v[i],v[j]);
                p2 = getIntersection(v[j],v[k]);
                p3 = getIntersection(v[i],v[k]);
                float dis1 = getdist(p1,p2),dis2=getdist(p2,p3),dis3 = getdist(p1,p3);
                
                if(dis1<= eps or dis2<=eps or dis3<=eps)
                     continue;
                ans = dis1+dis2+dis3;
                //cout << dis1 << ' ' << dis2 << ' ' << dis3 << '\n';
                maxans = max(maxans,ans);
            }
        }
    }
    if (maxans == -1) cout << "no triangle";
    else
        cout << fixed << setprecision(12) << maxans;
}

int main()
{

    proof;
    #ifndef ONLINE_JUDGE
    freopen("C:/Users/youss/OneDrive/Desktop/IO/input.txt", "r", stdin);
    freopen("C:/Users/youss/OneDrive/Desktop/IO/output.txt", "w", stdout);
    #endif
    //tests
        solve();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3984kb

input:

3
0 0 0 1
0 0 1 0
0 1 1 0

output:

no triangle

result:

wrong answer