Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

有点水,,,一排一排的打印,,ok

Posted by 1083595345 at 2015-05-31 17:54:07 on Problem 2380
Source Code

Problem: 2380		User: 1083595345
Memory: 24468K		Time: 2985MS
Language: C++		Result: Accepted
Source Code
#include <stdio.h>
#include <algorithm>

typedef long long ll;

typedef struct
{
    ll x,y,z;
}node;

node node1[500010];
node node2[500010];
ll b[500010];
ll a[500010];

bool cmp(node num1,node num2)
{
    return num1.x<num2.x;
}

bool cmp2(node num1,node num2)
{
    return num1.y<num2.y;
}

int main()
{
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%lld%lld%lld",&node1[i].x,&node1[i].y,&node1[i].z);
    std::sort(node1,node1+n,cmp);
    for(i=0;i<n;i++)
        node2[i]=node1[i];
    std::sort(node2,node2+n,cmp2);
    b[0]=-1;
    b[1]=node1[0].x;
    int k=1;
    for(j=1;j<n;j++)
        if(node1[j].x!=b[k])
            b[++k]=node1[j].x;
    for(j=0;j<k;j++)
        printf("%lld ",b[j]);
    printf("%lld\n",b[j]);
  //  printf("%d",b[0][2]);
    i=0;
    while(i<n)
    {
        // printf("%d\n",b[0][2]);
        for(j=0;j<100001;j++)
            a[j]=0;
         //printf("%d\n",b[0][2]);
        a[0]=node2[i].y;
        i++;
        while(node2[i].y==node2[i-1].y)
        {
            i++;
            if(i>=n)
                break;
        }
        int l=1;
        for(j=0;j<n;j++)
        {
            if(j>0 && node1[j].x!=node1[j-1].x)
                l++;
            
                //printf("%d %d %d\n",a[l],l,b[l]);
            if(node1[j].x==b[l] && node1[j].y==a[0])
                a[l]+=node1[j].z;
           // printf("%d %d %d %d %d %d\n",node1[j].x,b[l],node1[j].y,a[0],node1[j].z,a[l]);
        }
        for(j=0;j<k;j++)
            printf("%lld ",a[j]);
        printf("%lld\n",a[j]);
    }

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator