Submission #8057

# Submission time Handle Problem Language Result Execution time Memory
8057 2014-08-28T07:13:56 Z gs14004 Art Class (IOI13_artclass) C++
Compilation error
0 ms 0 KB
#include "artclass.h"
#include <cstdlib>
#include <cmath>
#define D(i,j,k,l) (abs(R[i][j] - R[k][l])+abs(G[i][j] - G[k][l])+abs(B[i][j] - B[k][l]))

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    double delta = 0;
    int meanR = 0, meanG = 0, meanB = 0, alldev = 0;
    int buckR[16] = {}, buckG[16] = {}, buckB[16] = {};
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            meanR += R[i][j];
            meanG += G[i][j];
            meanB += B[i][j];
            buckR[R[i][j]>>4]++;
            buckG[G[i][j]>>4]++;
            buckB[B[i][j]>>4]++;
        }
    }
    meanR /= H*W*16;
    meanG /= H*W*16;
    meanB /= H*W*16;
    for (int i=0; i<16; i++) {
        alldev += buckR[i] * (meanR - i)*(meanR - i);
        alldev += buckG[i] * (meanG - i)*(meanG - i);
        alldev += buckB[i] * (meanB - i)*(meanB - i);
    }
    alldev /= 256;
    for (int i=0; i<H; i++) {
        for (int j=0; j<W-1; j++) {
            double x = sqrt(D(i,j,i,j+1));
            if(x > 2.1 )delta += x;
        }
    }
    for (int j=0; j<W; j++) {
        for (int i=0; i<H-1; i++) {
            double x = sqrt(D(i,j,i+1,j));
            if(x > 2.1) delta += x;
        }
    }
    double t = 100.0 * delta / (2 * W * H - H - W);
    if(t > 660) return 3;
    else if(t > 400) return 2;
    else if(t < 140) return 4;
    else if(t > 250) return 1;
    else{ return alldev > 20000 ? 1 : 4;
    }
}


int main(){
    int W,H;
    int R[500][500], G[500][500], B[500][500];
    freopen("style-4-4.txt","r",stdin);
    scanf("%d %d",&H,&W);
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            scanf("%d %d %d",&R[i][j],&G[i][j],&B[i][j]);
        }
    }
    printf("%d",style(H,W,R,G,B));
}

// 321 [432] 416 311 [201] 339 271 203 255 [121 ~ 226]
// 465 495 [415] 443 [679] 535 461 569 454 [224 ~ 307]
// 916 [656] [963] 943 909 695 854 803 659 [296 ~ 377]
// 137 243 [111] [257] 159 194 221 203 212 [77 ~ 165] [409]

Compilation message

artclass.cpp: In function 'int main()':
artclass.cpp:54:33: error: 'stdin' was not declared in this scope
     freopen("style-4-4.txt","r",stdin);
                                 ^~~~~
artclass.cpp:54:33: note: suggested alternative: 'sin'
     freopen("style-4-4.txt","r",stdin);
                                 ^~~~~
                                 sin
artclass.cpp:54:5: error: 'freopen' was not declared in this scope
     freopen("style-4-4.txt","r",stdin);
     ^~~~~~~
artclass.cpp:54:5: note: suggested alternative: 'free'
     freopen("style-4-4.txt","r",stdin);
     ^~~~~~~
     free
artclass.cpp:55:5: error: 'scanf' was not declared in this scope
     scanf("%d %d",&H,&W);
     ^~~~~
artclass.cpp:55:5: note: suggested alternative: 'srand'
     scanf("%d %d",&H,&W);
     ^~~~~
     srand
artclass.cpp:61:5: error: 'printf' was not declared in this scope
     printf("%d",style(H,W,R,G,B));
     ^~~~~~
artclass.cpp:61:5: note: suggested alternative: 'rintf'
     printf("%d",style(H,W,R,G,B));
     ^~~~~~
     rintf