12月20号
Educational Codeforces Round 99 (Rated for Div. 2)B题
思路:我们观察样例可以发现其实每一次我们都可以把其中1~i的数变成-1这样的话会形成一个偏移量,这个偏移量会使原本的和向做移动i+1,但是对于i来说最小的偏移量也是2,所以如果我们算出来的sum只要不等于n+1我们都可以在i步完成没不然的话,我们只能推一步。
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
sum += i;
if (sum >= n)
{
if (sum == n + 1)
cout << i + 1 << endl;
else
cout << i << endl;
break;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round #708 (Div. 2)C1题
思维
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
void solve()
{
int n, k;
cin >> n >> k;
if (n % 2 == 0)
{
if (n % 4 == 0)
cout << n / 2 << ' ' << n / 2 / 2 << ' ' << n / 2 / 2 << endl;
else
cout << 2 << ' ' << (n - 2) / 2 << ' ' << (n - 2) / 2 << endl;
}
else
cout << 1 << ' ' << (n - 1) / 2 << ' ' << (n - 1) / 2 << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round #708 (Div. 2)B题
注意不要写错变量。
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int mp[N];
void solve()
{
int n, m;
cin >> n >> m;
for (int i = 0; i <= m; i++)
mp[i] = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
a[i] = x % m;
if (a[i] != 0)
mp[m - x % m]++;
else
mp[0]++;
}
int ans = 0;
//cout << mp[0] << ' ' << mp[m] << endl;
for (int i = 0; i < m; i++)
{
if ( i == 0)
{
if (mp[i])
{
ans++;
mp[i] = 0;
}
}
else if (!mp[i] || !mp[m - i])
{
if (!mp[i])
ans += mp[m - i];
else
ans += mp[i];
mp[i] = mp[m - i] = 0;
}
else
{
if (mp[i] > mp[m - i])
ans += mp[i] - (mp[m - i] + 1);
else if (mp[i] < mp[m - i])
ans += mp[m - i] - (mp[i] + 1);
ans++;
mp[i] = mp[m - i] = 0;
}
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}