美文网首页
codeforces 681 A

codeforces 681 A

作者: ChenKL | 来源:发表于2018-05-20 22:02 被阅读0次
A Good Contest CodeForces

简单题

判断大于2400 并且num1 < num2

#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int N;
    string con;
    int num1,num2;
    bool yes = false;
    cin >> N;
    for (int i = 0;i < N;i++)
    {
        cin >> con >> num1 >> num2;
       if (num1 >= 2400 && num1 < num2){
            yes = true;
        }
    }
    if (yes) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

B - Economy Game CodeForces

暴力枚举

#include <bits/stdc++.h>

using namespace std;
int coins[3] = {1234567,123456,1234};
int main()
{
    int num;
    cin >> num;
    for (int i = num / coins[1];i >= 0;i--)
    {
        int num1 = num - i * coins[0];
        for (int j = num1 / coins[1];j >= 0 ;j--)
        {
            int num2 = num1 - j * coins[1];
            if (num2 % coins[2] == 0)
            {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Heap Operations CodeForces

记录堆操作

坑点在于注意队列为空时的弹出 因此w了好几次

#include <bits/stdc++.h>

using namespace std;
const int MAX_N = 1e6 + 100;
string oper[MAX_N];
int nums[MAX_N];
int main()
{
  ios::sync_with_stdio ( false );
  priority_queue<int, vector<int>, greater<int> > que;
  int cnt = 0;
  int N;
  cin >> N;
  for ( int i = 0; i < N; i++ ) {
    string op;
    int num;
    cin >> op ;
    if ( op == "insert" ) {
      cin >> num;
      oper[cnt] = op;
      nums[cnt++] = num;
      que.push ( num );
    } else if ( op == "removeMin" ) {
      if ( !que.size() ) {
        oper[cnt] = "insert";
        nums[cnt++] = 0;
        oper[cnt] = op;
        nums[cnt++] = -1;
      } else {
        num = que.top();
        while ( que.size() && que.top() == num ) {
          oper[cnt] = op;
          nums[cnt++] = -1;
          que.pop();
        }
      }

    } else if ( op == "getMin" ) {
      cin >> num;
      while ( que.size() && que.top() < num ) {
        oper[cnt] = "removeMin";
        nums[cnt++] = -1;
        que.pop();
      }
      if ( !que.size() || que.top() != num ) {
        que.push ( num );
        oper[cnt] = "insert";
        nums[cnt++] = num;
      }
      oper[cnt] = "getMin";
      nums[cnt++] = num;

    }
  }
  cout << cnt << endl;
  for ( int i = 0; i < cnt; i++ ) {
    cout << oper[i];
    if ( oper[i] == "removeMin" ) {
      cout << endl;
    } else {
      cout << " " << nums[i] << endl;
    }
  }
  return 0;
}



相关文章

  • codeforces 681 A

    A Good Contest CodeForces 简单题 判断大于2400 并且num1 < num2 B - ...

  • CodeForces - 681C 【优先队列】

    传送门优先队列在语法(推入,删除)上与普通队列一样,不同在于声明时要这样:priority_queue ,grea...

  • 〔681〕

    2021/9/20 周一 小雨20℃ 一场秋雨,又是一场寒! 上午和小孩去妈妈家把发的东西送去一部分,过节嘛,...

  • 【Codeforces】Codeforces Round #53

    Problem A (div 2) 照着它说的做就行了。时间复杂度为 Problem B (div 2) 事实上只...

  • 【Codeforces】Codeforces Round #53

    Problem A 枚举所有可能的情况(枚举坐标对取余的结果),然后全部算出来取最大值即可。 时间复杂度为。 Pr...

  • CodeForces | Codeforces Global R

    不知不觉,也有一个多月没更新过了,现在打算一周更一次,整合自己在这一周的做题收获。(做题也只能是做很少的部分) 在...

  • 【Codeforces】Codeforces Round #53

    Problem A 分三种情况: 并且,由于必定有解,所以必定不会跟相等。所以直接输出和即可。 除此之外,如果,那...

  • 【Codeforces】Codeforces Round #53

    Problem A 从n个数的和,也就是入手。如果和为奇数,显然无法二等分,其最小的差只能为1。如果和为偶数,显然...

  • 【Codeforces】Codeforces Round #53

    Problem A 枚举每一个可能的t,然后验证取最小值即可。 时间复杂度为 Problem B 枚举所有可能的字...

  • 【Codeforces】Codeforces Round #53

    Problem A (div 2) 输出个就完事了。 时间复杂度为 Problem B (div 2) 首先找出尽...

网友评论

      本文标题:codeforces 681 A

      本文链接:https://www.haomeiwen.com/subject/xycxjftx.html