https://codeforces.com/contest/1106/problem/A
每次选取一个‘x’ 判断四角是不是’x’
#include <iostream>
#include <fstream>
using namespace std;
char matr[505][505];
bool check(int x,int y)
{
for(int i=-1; i<2; i++)
for(int j=-1; j<2; j++)
if(abs(i)==1&&abs(j)==1)
if(matr[i+x][j+y]!='X')
return false;
return true;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=0; i<n; i++)
cin>>matr[i];
int ans=0;
for(int i=0; i<n; i++)
for(int j=0 ; j<n ; j++)
if(matr[i][j] == 'X' )
if( check(i,j) )
ans++;
cout<<ans<<endl;
}
}
https://codeforces.com/contest/1106/problem/B
排序
#include <bits/stdc++.h>
using namespace std;
const long long maxn=1e5;
struct node
{
long long x,y,z;
} arr[maxn],tag[maxn];
bool cmp(node a,node b)
{
return a.y<b.y;
}
int main()
{
long long n,m;
while(cin>>n>>m)
{
for(long long i=0; i<n; i++)
{
cin>>arr[i].x;
}
for(long long i=0; i<n; i++)
{
cin>>arr[i].y;
tag[i].y=arr[i].y;
tag[i].z=i;
}
sort(tag,tag+n,cmp);
long long mx=0,x,y,s;
for(long long i=0; i<m; i++)
{
cin>>y>>x;
y--;
long long ans=0;
if(arr[y].x < x)
{
// cout<<"asd "<<endl;
ans+=arr[y].x*arr[y].y;
x-=arr[y].x;
arr[y].x=0;
long long mex;
if(mx<n)
{
mex=tag[mx].z;
while( x>arr[mex].x&&mx<n)
{
ans+=arr[mex].x*arr[mex].y;
x-=arr[mex].x;
arr[mex].x=0;
mx++;
mex=tag[mx].z;
}
if(mx<n)
{
ans+=x*arr[mex].y;
arr[mex].x-=x;
cout<<ans<<endl;
}
else
{
mx=n+10;
cout<<0<<endl;
}
}
else
cout<<"0"<<endl;
}
else
{
arr[y].x-=x;
cout<<arr[y].y*x<<endl;
}
// for(long long j=0;j<n;j++)
//cout<<arr[j].x<<' ';cout<<endl;
}
}
}
https://codeforces.com/contest/1106/problem/C
排序- - 大小 不想写
平方和最小 肯定是让每组数的大小尽可能平均 - -。
排序 两两组合就是最优 = = 可以证明。