codeforces 681 A

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;
}



?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    網事_79a3閱讀 12,230評論 3 20
  • 渲染: 1 當前屏幕渲染:在GPU的當前屏幕緩沖區中進行的渲染 2 離屏渲染:在GPU當前屏幕緩沖區外另建緩沖區渲...
    adrian920閱讀 400評論 0 0
  • import Foundation print("1","2","3","4"); //輸出多個字符串,并用“**...
    風的低語閱讀 479評論 0 0
  • 身姿窈窕舞婆婆,拂面輕盈戀逝波。 借得東皇施化雨,塘邊釣叟一時多。
    軍山老夫閱讀 174評論 3 0
  • 駝鈴搖,敦煌夢 月牙泉水映著月光,郁郁蔥蔥的蘆葦隨風輕輕擺動,夜晚沙漠寂靜清冷,只有泉邊幾攤篝火忽明忽滅,商旅們支...
    小晴天牙牙閱讀 467評論 0 1