codeforces打卡(一)

12月13号
Codeforces Round #772 (Div. 2)C题

#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define int long long
const int N = 2e5 + 10;
int a[N];
vector<int> v;

void solve()
{
     int n;
     cin >> n;
     int flag = 1;
     for (int i = 1; i <= n; i++)
     {
          cin >> a[i];
          if (i > 1 && a[i] < a[i - 1])
          {
               flag = 0;
          }
     }
     if (flag)
     {
          cout << 0 << endl;
          return;
     }
     if (a[n] < a[n - 1] || (a[n] < 0 && a[n - 1] < 0))
     {
          cout << "-1" << endl;
     }
     else
     {
          cout << n - 2 << endl;
          for (int i = 1; i <= n - 2; i++)
          {
               cout << i << ' ' << n - 1 << ' ' << n << endl;
          }
     }
}

signed main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int T;
     cin >> T;
     while (T--)
     {
          solve();
     }
     return 0;
}

Codeforces Round #758 (Div.1 + Div. 2)B题

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;
int ans[N];

void solve()
{
     int n, a, b;
     cin >> n >> a >> b;
     if (abs(a - b) > 1 || (a + b) > n - 2)
     {
          cout << -1 << endl;
          return;
     }
     else
     {
          int i = 1, l = 1, r = n;
          if (a == b)
          {
               while(i<=2*a)  ans[i++]=l++,ans[i++]=r--;
               for(;i<=n;)    ans[i++]=l++;
          }
          else
          {
               if(a>b)
               {
                    while(i<=2*b)  ans[i++]=l++,ans[i++]=r--;
                    for(;i<=n;)    ans[i++]=l++;
                    swap(ans[n-1],ans[n]);
               }
               else
               {
                    while(i<=2*a)  ans[i++]=r--,ans[i++]=l++;
                    for(;i<=n;)    ans[i++]=r--;
                    swap(ans[n-1],ans[n]);
               }
          }
          for(int i=1;i<=n;i++)    cout<<ans[i]<<' ';
          cout<<endl;
     }
}

int main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int T;
     cin >> T;
     while (T--)
     {
          solve();
     }
     return 0;
}

https://codeforces.com/problemset/problem/1592/B题

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;
int a[N], b[N];

void solve()
{
     int n, x;
     cin >> n >> x;
     for (int i = 0; i < n; i++)
     {
          cin >> a[i];
          b[i] = a[i];
     }
     sort(b, b + n);
     int flag = 1;
     for (int i = n - x; i < x; i++)
     {
          if (a[i] != b[i])
          {
               flag = 0;
               break;
          }
     }
     if (flag)
          cout << "YES" << endl;
     else
          cout << "NO" << endl;
}

int main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int T;
     cin >> T;
     while (T--)
     {
          solve();
     }
     return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值