codeforces 681 A
2018-05-20 本文已影响0人
ChenKL
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;
}