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 }
  • 相关阅读:
    Andoid自动判断输入是电话,网址或者Email的方法--Linkify
    Activity LifeCycle
    Android Log详解(Log.v,Log.d,Log.i,Log.w,Log.e)
    Android应用自动更新功能的实现!
    Android Layout: TableLayout
    Android实现动态改变屏幕方向(Landscape & Portrait)
    Android Intent 总结
    Android中Intent传递对象的两种方法:Serializable & Parcelable
    Activity的setResult方法
    css3中的calc()
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/9364729.html
Copyright © 2011-2022 走看看