제출 #401637

#제출 시각아이디문제언어결과실행 시간메모리
401637rqi미술 수업 (IOI13_artclass)C++14
0 / 100
112 ms12872 KiB
#include "artclass.h" #include <bits/stdc++.h> using namespace std; typedef long double db; #define mp make_pair #define f first #define s second #define pb push_back int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int H; int W; int col[500][500][3]; db avg_diff[500][500]; db avg_pix[3]; db getContrast(){ db avg_tot = 0; int avg_num = 0; for(int i = 1; i+1 < H; i++){ for(int j = 1; j+1 < W; j++){ db tot_diff = 0; for(int dir = 0; dir < 8; dir++){ for(int k = 0; k < 3; k++){ tot_diff+=abs(col[i][j][k]-col[i+dx[dir]][j+dy[dir]][k]); } } avg_diff[i][j] = tot_diff/db(8*3); avg_tot+=avg_diff[i][j]; avg_num++; } } return avg_tot/avg_num; } void getAvgPix(){ db tot = 0; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ for(int k = 0; k < 3; k++){ avg_pix[k]+=col[i][j][k]; } tot+=1; } } for(int k = 0; k < 3; k++){ avg_pix[k]/=tot; } } pair<db, db> contrast_rang[4] = {mp(3.19, 11.8), mp(8.8, 20.3), mp(21.3, 42.9), mp(1.43, 3.3)}; db score[4]; pair<db, db> bright_rang[4] = {mp(126.7, 202), mp(68.6, 111.0), mp(100.9, 191.6), mp(48.3,161.9)}; db getPropOff(pair<db, db> a, db b){ db a_mid = (a.f+a.s)/2; db a_diff = (a.s-a_mid); return abs(b-a_mid)/a_diff; } int style(int _H, int _W, int _R[500][500], int _G[500][500], int _B[500][500]) { cout << fixed << setprecision(1); H = _H; W = _W; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ col[i][j][0] = _R[i][j]; col[i][j][1] = _G[i][j]; col[i][j][2] = _B[i][j]; } } db contrast = getContrast(); cout << contrast << "\n"; getAvgPix(); cout << avg_pix[0] << " " << avg_pix[1] << " " << avg_pix[2] << "\n"; db bright = (avg_pix[0]+avg_pix[1]+avg_pix[2])/3; cout << bright << "\n"; for(int i = 0; i < 4; i++){ score[i] = getPropOff(contrast_rang[i], contrast)+getPropOff(bright_rang[i], bright); } vector<pair<db, int>> sorted_scores; for(int i = 0; i < 4; i++){ sorted_scores.pb(mp(score[i], i)); } sort(sorted_scores.begin(), sorted_scores.end()); for(int i = 0; i < 4; i++){ cout << sorted_scores[i].f << " " << sorted_scores[i].s+1 << "\n"; } return sorted_scores[0].s+1; }
#Verdict Execution timeMemoryGrader output
Fetching results...