zoukankan      html  css  js  c++  java
  • Triangle Partition

    Triangle Partition

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)
    Total Submission(s): 1107    Accepted Submission(s): 556
    Special Judge


    Problem Description
    Chiaki has 3n points p1,p2,,p3n. It is guaranteed that no three points are collinear.
    Chiaki would like to construct n disjoint triangles where each vertex comes from the 3n points.
     
    Input
    There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
    The first line contains an integer n (1n1000) -- the number of triangle to construct.
    Each of the next 3n lines contains two integers xi and yi (109xi,yi109).
    It is guaranteed that the sum of all n does not exceed 10000.
     
    Output
    For each test case, output n lines contain three integers ai,bi,ci (1ai,bi,ci3n) each denoting the indices of points the i-th triangle use. If there are multiple solutions, you can output any of them.
     
    Sample Input
    1
    1
    1 2
    2 3
    3 5
     
    Sample Output
    1 2 3
     
    Source
     
     
    按x排下序就可以了,然后按次序输出三个
     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 #define N 3005
     5 using namespace std;
     6 struct Node{
     7     int x,y;
     8     int in;
     9 }node[N];
    10 
    11 bool cmp(Node a,Node b){
    12     if(a.x == b.x){
    13         return a.y<b.y;
    14     }
    15     return a.x<b.x;
    16 }
    17 
    18 int main(){
    19     int t;
    20     while(cin>>t){
    21         while(t--){
    22             memset(node,0,sizeof(node));
    23             int n;
    24             cin>>n;
    25             for(int i=0;i<3*n;i++){
    26                 cin>>node[i].x>>node[i].y;
    27                 node[i].in = i+1;
    28             }
    29             sort(node,node+3*n,cmp);
    30             for(int i=0;i<3*n;i=i+3){
    31                 cout<<node[i].in<<" "<<node[i+1].in<<" "<<node[i+2].in<<endl;
    32             }
    33         }
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    BZOJ 2599: [IOI2011]Race [点分治]
    BZOJ 2152: 聪聪可可 [点分治]
    POJ1741Tree [点分治]【学习笔记】
    论避免手写堆的各种姿势(1)
    BZOJ 1835: [ZJOI2010]base 基站选址 [序列DP 线段树]
    Jmeter参数化
    Manjaro Linux执行某些命令缺少libtinfo.so.5问题
    Nmon的安装及使用
    JMeter性能测试-服务器资源监控插件详解
    linux 服务器性能监控(一)
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/9364729.html
Copyright © 2011-2022 走看看