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

我的这种写法你能看懂算我输,虽然很短

Posted by nka_kun at 2017-08-06 20:05:22 on Problem 3723
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const int ff = 0x3f3f3f3f;
typedef struct
{
    int b;
    int g;
    int w;
} node1;


int n,m,k;
int visb[10005],visg[10005];
node1 re[50005];

bool cmp(node1 a,node1 b)
{
    return a.w> b.w;
}

void init()
{
    memset(visg,0,sizeof(visg));
    memset(visb,0,sizeof(visb));
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        init();
        scanf("%d %d %d",&n,&m,&k);
        for(int i = 1;i<= k;i++)
        {
            scanf("%d %d %d",&re[i].g,&re[i].b,&re[i].w);
        }
        sort(re+1,re+k+1,cmp);
        int sum = 0;
        for(int i = 1;i<= k;i++)
        {
            if(re[i].g>= n||re[i].b>= m)
                continue;
            if(!visg[re[i].g]&&!visb[re[i].b])
            {
                sum+= (20000-re[i].w);
                visg[re[i].g] = 1;
                visb[re[i].b] = 1;
            }
            else if(!visg[re[i].g]&&visb[re[i].b]||visg[re[i].g]&&!visb[re[i].b])
            {
                sum+= (10000-re[i].w);
                visg[re[i].g] = 1;
                visb[re[i].b] = 1;
            }
            else if(visg[re[i].g]&&visb[re[i].b])
                continue;
        }
        for(int i = 0;i< n;i++)
            if(!visg[i])
                sum+= 10000;
        for(int i = 0;i< m;i++)
            if(!visb[i])
                sum+= 10000;
        printf("%d\n",sum);
    }



    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