一开始做的蛮好的,上来切掉了A和C,然后告诉你unrated了,啊啊啊,想哭。
A. Inscribed Figures
就是多几个if判断,有一个3,1,2顺序需要特别判断的
#include<bits/stdc++.h>
using namespace std;
int x[100];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
#endif
int n,ans = 0;
cin >> n;
for(int i = 0;i < n; i++)
{
cin >> x[i];
if(i > 0)
{
if(x[i-1] == 1 && x[i] == 2)
ans += 3;
else if(x[i-1] == 1 && x[i] == 3)
ans += 4;
else if(x[i-1] == 2 && x[i] == 1)
ans += 3;
else if(x[i-1] == 3 && x[i] == 1)
ans += 4;
else
ans = -5000;
}
if(i > 1)
{
if(x[i] == 2 && x[i-1] == 1 && x[i-2] == 3)
ans -= 1;
}
}
if(ans >= 0)
cout << "Finite" << endl << ans << endl;
else
cout << "Infinite" << endl;
return 0;
}
B. Ugly Pairs
把字母按奇偶排序,然后连成串就可以了,比赛的时候真的是想破脑袋,不知道什么情况
#include<bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif
int t;
cin >> t;
while(t--)
{
string s,ou,ji;
cin >> s;
sort(s.begin(),s.end());
for(int i = 0;i < s.length(); i++)
{
if(s[i] % 2 == 0)
ou += s[i];
else
ji += s[i];
}
if(ji.empty() || ou.empty())
cout << ji + ou << endl;
else if(abs(ou.back() - ji[0]) != 1)
cout << ou + ji << endl;
else if(abs(ji.back() - ou[0]) != 1)
cout << ji + ou << endl;
else
cout << "No answer" << endl;
}
return 0;
}
C. Match Points
简单按照题意进行模拟就完事了。
#include<bits/stdc++.h>
#pragma disable:4996)
using namespace std;
multiset<int> b;
multiset<int>::iterator iter;
int a[200010];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int t = n / 2;
for (int i = t; i < n; i++)
b.insert(a[i]);
int ans = 0;
for (int i = 0; i < t; i++)
{
int f = a[i] + m;
iter = b.lower_bound(f);
if (iter == b.end())
{
cout << ans << endl;
return 0;
}
b.erase(iter);
ans++;
}
cout << ans << endl;
return 0;
}