水杯 (模拟) (智算之道初赛高校组第三场)

传送门

共 20 个测试点 每个测试点 5 分
每个测试点限时 1 秒 运行内存上限 512MB

小小 D有一个能显示温度的杯子. 其原理是杯盖上的一个传感器. 只有在杯子内的水的体积大于等于某个数 L 的时候传感器才能显示水温,并且如果水温不在 [A,B] 内传感器也无法显示水温.
注意,这里温度对水的体积没有影响
初始水杯为空,有 n次操作,操作分为三种:

  • 1 x 表示把水温变成 x.
  • 2 x 表示把水的体积变成 x.
  • 3 查询传感器的显示情况. 如果不能显示水温输出 G,否则输出水温.

输入格式
第一行四个整数 n,L,A,B,含义如题目所示.
接下来 n 行,每行一个整数 opt 或两个整数 opt,x,表示执行操作 opt.

输出格式
对于所有操作 3 输出结果,每行一个答案.

数据规模与约定
对于 100% 的数据,31≤n≤1000,−273≤A≤B≤100,1≤L≤1000,1≤opt≤3.
对于操作 1,−273≤x≤100;对于操作 2,1≤x≤1000.

样例输入
5 2 1 3
1 5
2 3
3
1 2
3
样例输出
GG
2

思路: 感觉也没什么好说的,就是简单的模拟即可。

代码实现:

#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int  inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll   mod = 1e9 + 7;
const int  N = 2e5 + 5;

int n, l, a, b, tj, sw;

signed main()
{
    IOS;

    cin >> n >> l >> a >> b;
    while(n --){
        int op, x; cin >> op;
        if(op == 3){
            if(tj >= l && a <= sw && sw <= b) cout << sw << endl;
            else cout << "GG" << endl;
            continue;
        }
        cin >> x;
        if(op == 1) sw = x;
        else tj = x;
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Satur9/article/details/107625046