結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 2018-07-02 19:28:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,786 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 63,804 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 01:36:26 |
合計ジャッジ時間 | 1,027 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
#include <iostream> #include <cstdio> #include <climits> #include <algorithm> #include <math.h> using namespace std; int main(){ int h,w; cin>>h>>w; // scanf("%d",&h); // scanf("%d",&w); char paper[52][52]={}; // string asas; // getline(&asas); getchar(); // getchar(); // getchar(); for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ //cin>>paper[j][i]; paper[j][i]=getchar(); // scanf("%c",paper[j][i]); // printf("-%c-",paper[j][i]); } getchar(); } double tem,ans=999999999999.9; for(int k=1;k<=w;k++){ tem=0; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(paper[j][i]!='0'){ tem+=sqrt((k-j)*(k-j)+(i-0)*(i-0)); } } } ans=min(ans,tem); } for(int k=1;k<=w;k++){ tem=0; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(paper[j][i]!='0'){ tem+=sqrt((k-j)*(k-j)+(i-(h+1))*(i-(h+1))); } } } ans=min(ans,tem); } for(int k=0;k<=w;k++){ tem=0; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(paper[j][i]!='0'){ tem+=sqrt((0-j)*(0-j)+(i-k)*(i-k)); } } } ans=min(ans,tem); } for(int k=0;k<=w;k++){ tem=0; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(paper[j][i]!='0'){ tem+=sqrt(((w+1)-j)*((w+1)-j)+(i-k)*(i-k)); } } } ans=min(ans,tem); } // cout<<ans<<endl;; printf("%f",ans); return 0; }