• 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 }
  • 相关阅读:
    C#窗体操作的小技巧
    C#操作Xml
    Path类对路径字符串的操作
    Google Maps 基础
    C#时间操作总结
    根据地理坐标计算瓦片行列号
    使用VBA宏批量修改表格
    检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法
    Asp.net实现URL重写
    VS2013利用ajax访问不了json文件——VS2013配置webconfig识别json文件
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/9364729.html
Copyright © 2020-2023  润新知