Codeforces打卡(五)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值