Codeforces Round #217 (Div. 2)
A. Rook, Bishop and King
題意:rook只能橫著或者豎著走任意多個格,bishop只能走對角線任意多個格,king可以橫著、豎著、對角線走,一次只能走一格,給你起點、終點的座標,問這三個最少幾步能走到。
思路:主要是bishop有些麻煩,如果bishop的橫座標的和減去縱座標的和是偶數的話,2步可以到達,其他情況也比較簡單。
下面是程式碼:
思路:主要是bishop有些麻煩,如果bishop的橫座標的和減去縱座標的和是偶數的話,2步可以到達,其他情況也比較簡單。
下面是程式碼:
#include<iostream>
#include<cmath>
using namespace std;
int r1,r2,c1,c2;
int num1,num2,num3;
int Abs(int a)
{
return a>0?a:(-a);
}
int rooknum()
{
if(r1==r2||c1==c2)
return 1;
return 2;
}
int bishopnum()
{
if(Abs(r1-r2)==Abs(c1-c2))
return 1;
if(Abs((r1+r2)-(c1+c2))%2==0)
return 2;
return 0;
}
int kingnum()
{
int ans=0;
int min1=min(Abs(r1-r2),Abs(c1-c2));
ans+=min1;
ans+=Abs(Abs(r1-r2)-Abs(c1-c2));
return ans;
}
int main()
{
num1=0,num2=0,num3=0;
cin>>r1>>c1>>r2>>c2;
num1=rooknum();
num2=bishopnum();
num3=kingnum();
cout<<num1<<' '<<num2<<' '<<num3<<endl;
return 0;
}
B. Berland Bingo
感覺自己做的好麻煩。。。
#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
using namespace std;
const int MAXN=110;
vector<int> v[MAXN];
int n;
bool met[MAXN];
void metV(vector<int> & v)
{
memset(met,0,sizeof(met));
for (int i=0; i<v.size(); i++)
met[v[i]]=true;
}
bool check(vector<int> & v)
{
for (int i=0; i<(int)v.size(); i++)
if (!met[v[i]]) return true;
return false;
}
int main()
{
cin >> n;
for (int i=0; i<n; i++)
{
int m;
cin >> m;
v[i].resize(m);
for (int j=0; j<m; j++)
cin >> v[i][j];
}
for (int i=0; i<n; i++)
{
metV(v[i]);
bool key=true;
for (int j=0; j<n; j++)
{
if (i==j) continue;
if (!check(v[j]))
{
key=false;
break;
}
}
if (key) cout << "YES";
else cout << "NO";
cout << endl;
}
return 0;
}
相關文章
- Codeforces Round #541 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 948 (Div. 2)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round 987 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 986 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 969 (Div. 2)
- Codeforces Round 873 (Div. 2)
- Codeforces Round 967 (Div. 2)
- Codeforces Round 965 (Div. 2)
- Codeforces Round 963 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 949 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 945 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round 947 (Div. 1 + Div. 2)
- Codeforces Round 941 (Div. 2) D
- Codeforces Round 932 (Div. 2) ABCD
- Codeforces Round 945 (Div. 2) (A - E)
- Codeforces Round 892 (Div. 2) E
- Codeforces Round 936 (Div. 2) E
- 2024.11.15 Codeforces Round 987(Div. 2)