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 Liuzhaoliang at 2014-10-14 05:03:56 on Problem 1916
然后滑动窗口就过了。
#include<iostream>
#include<stdio.h>
using namespace std;
const int N = 1025;
int d,n;
int rat[1030][1030];
int A[1030];
//sweep line top and down
int main()
{
    int t,x,y,cnt;
    scanf("%d",&t);
    while(t--){
        memset(A,0,sizeof A);
        memset(rat,0,sizeof rat);
        scanf("%d%d",&d,&n);
        // 1 .. 1025
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&x,&y,&cnt);
            rat[x+1][y+1] = cnt;
        }
        for(int i=1;i<=d+1;i++)
            for(int j=1;j<=N;j++)
                A[j]+=rat[i][j];
        int l_cnt = d+1;
        
        int best = -1;
        for(int i=1;i<=N;i++){
            int win = 0;
            for(int j=1;j<=d+1;j++) win+=A[j];
            int r_cnt = d+1;
            for(int j=1;j<=1025;j++){
                if(win>best) best = win, x=i,y=j;
                if(r_cnt==2*d+1) win-=A[j-d],r_cnt--;
                if(j+d+1<=1025) r_cnt++, win+=A[j+d+1];
            }
            if(l_cnt == 2*d+1){
                for(int j=1;j<=1025;j++)
                    A[j] -= rat[i-d][j];
                l_cnt--;
            }
            if(i+d+1<=1025){
                l_cnt++;
                for(int j=1;j<=1025;j++)
                    A[j] += rat[i+d+1][j];
            }
            
        }
        printf("%d %d %d\n",x-1,y-1,best);
    }
    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