Educational Codeforces Round 44 (Rated for Div. 2)
- A. Chess Placing
#include <bits/stdc++.h>
using namespace std;
const int MAXN=205;
int a[MAXN];
int main()
{
int n;
int odd=1,even=2,oddsum=0,evensum=0;
cin>>n;
for(int i=1;i<=(n/2);i++)
{
cin>>a[i];
}
sort(a+1,a+n/2+1);
for(int i=1;i<=n/2;i++)
{
oddsum+=abs(a[i]-odd);odd+=2;
evensum+=abs(a[i]-even);even+=2;
}
cout<<min(oddsum,evensum)<<endl;
return 0;
}
- B. Switches and Lamps
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3000;
char c[MAXN][MAXN];
int flag[MAXN];
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>c[i][j];
}
}
for(int j=0;j<m;j++)
{
int cnt=0;
for(int i=0;i<n;i++)
{
if(c[i][j]=='1')cnt++;
}
if(cnt==1)
{
for(int i=0;i<n;i++)
{
if(c[i][j]=='1')
flag[i]=1;
}
}
}
for(int i=0;i<n;i++)
if(flag[i]==0)
{
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
return 0;
}
- C. Liebig’s Barrels
//二分+贪心
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL maxn=100005;
LL a[maxn];
bool book[maxn];
int main()
{
LL n,k,l;
cin>>n>>k>>l;
for(LL i=1;i<=n*k;i++)
{
cin>>a[i];
}
sort(a+1,a+n*k+1);
//先保证n个桶差值小于l
LL ans=0;
if(a[n]-a[1]>l)
{
cout<<0<<endl;
return 0;
}
else
{
// LL tmp;
// for(LL i=1;i<=n*k;i++)
// {
// if(a[i]-a[1]>l)tmp=i-1;
// }
// cout<<tmp<<endl;
LL t=upper_bound(a+1,a+n*k+1,l+a[1])-a;
//cout<<t<<" "<<a[t]<<endl;
t=t-1;
LL flag=0;
for(LL i=1;i<=t;i+=k)
{
ans+=a[i];flag++;
book[i]=true;
if(flag==n)break;
}
for(LL j=t;j>=1;j--)
{
if(flag==n)break;
if(!book[j])
{
ans+=a[j];
flag++;
}
if(flag==1)break;
}
cout<<ans<<endl;
}
return 0;
}