Codeforces #644 div3
听说是div4改成的div3,然而我还是没有ak…
A
题目链接
思路:规律题
ACcodes:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int test = 1;
int n;
int a,b;
int main()
{
scanf("%d",&test);
while(test--)
{
cin >> a >> b;
int s = min(max(2*a,b),max(2*b,a));
cout << s*s << endl;
}
return 0;
}
B
题目链接
思路:先排序,再找出两个相邻元素的最小差值
ACcodes:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3+10;
int test = 1;
int n,a[N];
int main()
{
scanf("%d",&test);
while(test--)
{
cin >> n;
for(int i=1;i<=n;i++)
cin >> a[i];
sort(a+1,a+1+n);
int res = a[2] - a[1];
for(int i=1;i<n;i++)
res = min(a[i+1]-a[i],res);
cout << res << endl;
}
return 0;
}
C
题目链接
思路:统计奇数偶数的个数,如果都为偶,直接yes;否则,检查奇数中的元素,与它相邻的偶数是否出现在数组中。
ACcodes:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int test = 1;
int n,a[N];
int main()
{
scanf("%d",&test);
while(test--)
{
bool flag = false;
int vis[105] = {0};
cin >> n;
for(int i=1;i<=n;i++)
cin >> a[i],vis[a[i]]++;
vector<int> p,q; // q is even, p is odd
for(int i=1;i<=n;i++)
{
if(a[i]%2)
p.push_back(a[i]);
else
q.push_back(a[i]);
}
if(p.size()%2==0)
{
cout << "YES" << endl;
continue;
}
for(int i=0;i<p.size();i++)
{
if(vis[p[i]-1] || vis[p[i]+1])
{
flag = true;
break;
}
}
cout << (flag?"YES":"NO") << endl;
}
return 0;
}
D
题目链接
思路:找出n的小于k的最大因子
ACcodes:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int test = 1;
bool isprime(int num)
{
if (num < 3)
return num > 1;
if (num % 6 != 1 && num % 6 != 5)
return false;
int sq = (int)sqrt(num);
for(int i=5;i<=sq;i+=6)
{
if (num % i == 0 || num % (i + 2) == 0)
return false;
}
return true;
}
int n,k;
int main()
{
scanf("%d",&test);
while(test--)
{
int res;
scanf("%d%d",&n,&k);
if(n<=k)
{
cout << 1 << endl;
continue;
}
set<int> q;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
q.insert(i);
q.insert(n/i);
}
}
for(auto it : q)
{
if(it>k)
break;
else
res = n/it;
}
cout << res << endl;
}
return 0;
}
E
题目链接
思路:对于一个为1的位置,判断它的右和下是否为0,若是则为no
ACcodes:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;cin >> t;
while (t--) {
int n;cin >> n;
string s[n], ans = "YES\n";
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n - 1; ++i) for (int j = 0; j < n - 1; ++j)
if (s[i][j] == '1' && s[i][j + 1] == '0' && s[i + 1][j] == '0') ans = "NO\n";
cout << ans;
}
}
F
题目链接
思路:构造
ACcodes:
#include <bits/stdc++.h>
using namespace std;
string s[15];
int n,m;
int check(string ss){
for(int i=0;i<n;i++){
int cnt=0;
for(int j=0;j<m;j++){
if(ss[j]!=s[i][j]) cnt++;
}
if(cnt>1) return 0;
}
return 1;
}
int main(){
int t;
cin>>t;
while(t--){
int flag=0;
cin>>n>>m;
for(int i=0;i<n;i++) cin>>s[i];
for(int i=0;i<m;i++){
if(flag) break;
for(char c='a';c<='z';c++){
string t=s[0];
t[i]=c;
if(check(t)){
cout<<t<<endl;
flag=1;
break;
}
}
}
if(!flag) cout<<-1<<endl;
}
}