生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #644 (Div. 3)(A-E)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這場的A-E都是水題,就簡單記錄一下吧。
Minimal Square CodeForces - 1360A
思路:我們令b=max(a,b),a=min(a,b).
如果b>=2*a的話,最終答案就是b * b,否則就是4 * a * a
代碼如下:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;int a
,b
;int main()
{int t
;scanf("%d",&t
);while(t
--){scanf("%d%d",&a
,&b
);if(a
>b
) swap(a
,b
);if(b
>=2*a
) cout
<<b
*b
<<endl
;else cout
<<4*a
*a
<<endl
;}return 0;
}
Honest Coach CodeForces - 1360B
思路:排序之后,找到相差最少的就可以了。
代碼如下:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;const int maxx
=100;
int a
[maxx
];
int n
;int main()
{int t
;scanf("%d",&t
);while(t
--){scanf("%d",&n
);for(int i
=1;i
<=n
;i
++) scanf("%d",&a
[i
]);sort(a
+1,a
+1+n
);int _max
=1e9;for(int i
=2;i
<=n
;i
++) _max
=min(_max
,a
[i
]-a
[i
-1]);printf("%d\n",_max
);}return 0;
}
Similar Pairs CodeForces - 1360C
思路:分奇偶儲存,如果都是偶數的話就可以,如果不是的話,那么就找是否有一個奇數一個偶數相差1.
代碼如下:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;const int maxx
=51;
int a
[maxx
],b
[maxx
];
int n
;int main()
{int t
;scanf("%d",&t
);while(t
--){scanf("%d",&n
);int cnt0
=0,cnt1
=0;int x
;for(int i
=1;i
<=n
;i
++){scanf("%d",&x
);if(x
&1) a
[++cnt0
]=x
;else b
[++cnt1
]=x
;}if(cnt1
%2==0) cout
<<"YES"<<endl
;else{int flag
=0;for(int i
=1;i
<=cnt0
;i
++){for(int j
=1;j
<=cnt1
;j
++){if(abs(a
[i
]-b
[j
])==1){flag
=1;break;}}if(flag
) break;}if(flag
) cout
<<"YES"<<endl
;else cout
<<"NO"<<endl
;}}return 0;
}
Buying Shovels
思路:如果說k>=n的話,直接輸出1就可以了。否則就找n在[1,k]內最大的因子。
代碼如下:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;int n
,k
;int main()
{int t
;scanf("%d",&t
);while(t
--){scanf("%d%d",&n
,&k
);if(n
<=k
) cout
<<1<<endl
;else{int _max
=0;for(int i
=1;i
<=sqrt(n
)&&i
<=k
;i
++) {if(n
%i
==0){_max
=max(_max
,i
);if(n
/i
<=k
) _max
=max(_max
,n
/i
);}}cout
<<n
/_max
<<endl
;}}return 0;
}
Polygon
思路:看圖即可,能否拼湊出當前的狀態。如果1右邊和下面都沒有1的話,這是不行的(除了邊界)。
代碼如下:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;const int maxx
=51;
char s
[maxx
][maxx
];
int n
;int main()
{int t
;scanf("%d",&t
);while(t
--){scanf("%d",&n
);for(int i
=0;i
<n
;i
++) scanf("%s",s
[i
]);int flag
=1;for(int i
=0;i
<n
;i
++){for(int j
=0;j
<n
;j
++){if(s
[i
][j
]=='1'){if(i
==n
-1||j
==n
-1) continue;if(s
[i
+1][j
]=='1'||s
[i
][j
+1]=='1') continue;flag
=0;}}}if(flag
) cout
<<"YES"<<endl
;else cout
<<"NO"<<endl
;}return 0;
}
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Codeforces Round #644 (Div. 3)(A-E)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。