8.24-河西校区

· · 个人记录

8.24-河西校区

::::::info[T1]{open}

T640711 快递费用

::::info[题意] 某邮寄公司按物品重量和目的地区域收费。

重量标准为:

不足 500 克 20 元,超过 500 克的,超重的部分按每 500 克加收费用。超出的重量不足 500 克的,按 500 克计算。

目的地区域标准: 区域 1:每超重 500 克加收 4 元;

区域 2:每超重 500 克加收 6 元;

区域 3:每超重 500 克加收 9 元;

区域 4:每超重 500 克加收 10 元;

区域 5:每超重 500 克加收 17 元。
::::info[思路]
按照题意模拟即可。
::::
::::success[赛时代码&得分]
$$
\color{green}{Accepted\not100tps}
$$
#include <bits/stdc++.h>
using namespace std;
int x, y, z = 20;
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> x >> y;
    if (y == 1) 
        y = 4;
    else if (y == 2) 
        y = 6;
    else if (y == 3)
        y = 9;
    else if (y == 4) 
        y = 10;
    else 
        y = 17;
    x -= 500;
    while (x > 0) {
        x -= 500;
        z += y;
    } 
    cout << z;
    return 0;
}
::::

::::::info[T2]{open}

T638889 石头布没有剪刀

::::info[题意] 你和对手都只有两种出拳方式:石头 g 和布p,规则一样,赢了得一分,平局不得分,输了减一分。 现给你对手的出拳方式,在对于任意位置 i 满足你出过的石头的次数大于你出过的布的次数时,输出你能得到的最大分数。 :::: ::::warning[赛时得分]

\color{red}{Unaccepted\not0tps}

:::: ::::info[思路] 能出布就出布。 :::: ::::success[正解]

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
string s;
int cnt1, cnt2, sc;
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i ++) 
        if (s[i] == 'g') 
            if (cnt1 == cnt2) 
                cnt1 ++;
            else {
                cnt2 ++;
                sc ++;
            }
        else 
            if (cnt1 == cnt2) {
                cnt1 ++;
                sc --;
            } else 
                cnt2 ++;
    cout << sc;
    return 0;
}
::::

::::::info[T3]{open}

T644252 篝火问题

::::info[题意] 在一个二维平面上,原点存在一个篝火,会不停地在这一格产生烟雾。每秒都有风把烟雾吹向四方,风速一秒一格。

求在观测点 x, y 是否有烟雾。
::::warning[赛时得分]
根本没写。
$$
\color{red}{Unaccepted\not0tps}
$$
::::
::::info[思路]
由于一个一个模拟烟雾移动太费时间,故利用题目所说“求观测点是否有烟雾”和相对运动,只移动篝火和人。
::::
::::success[正解]
```cpp line-numbers
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
map<pair<int, int>, bool> mp;
int n, r, c, x, y, _1, _2;
char C;
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> r >> c;
mp[{x, y}] = 1;
for (int i = 1; i <= n; i ++) {
cin >> C;
if (C == 'N') {
x ++;
r ++;
} else if (C == 'S') {
x --;
r --;
} else if (C == 'W') {
y ++;
c ++;
} else if (C == 'E') {
y --;
c --;
}
mp[{x, y}] = 1;
if (mp.count({r, c}))
cout << 1;
else
cout << 0;
}
return 0;
}
```
::::
::::::

::::::info[T4]{open}

T639146 落落的去的数学问题3

::::info[题意] 定义 f(x, y) 如下:

将 x, y 的十进制表示分别作为字符串解释,并按顺序连接,得到字符串 z。将 z 作为十进制整数解释,其值即为 f(x, y)。

给定一个长度为 N 的正整数序列 A=(A_1,\ldots,A_N)。请计算下式的值对 998244353 取模的结果:

\sum_{i=1}^{N-1}\sum_{j=i+1}^N f(A_i,A_j)

:::: ::::warning[赛时得分] 暴力。

\color{red}{Unaccepted\not10tps}

:::: ::::info[思路] 对于每一个 2 \le j \le n ,前缀和预处理所有 j 之前的 a_i ,统一做乘法运算。 :::: ::::success[正解]

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, mod = 998244353;
ll n, ans;
ll a[N], b[N];
int f(int x, int y) {
    string a = i2s(x), b = i2s(y);
    ll res = s2l(a + b);
    res %= mod;
    return res;
}
ll gtl(ll x) {
    ll cnt = 0;
    for (; x; cnt ++) 
        x /= 10;
    return cnt;
}
ll p(ll x) {
    ll res = 1;
    for (ll i = 1; i <= x; i ++) 
        res = (res * 10);
    return res % mod;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        b[i] = (b[i - 1] + a[i]) % mod;
    }
    for (int j = 2; j <= n; j ++) {
        ll len = gtl(a[j]);
        ans += (b[j - 1] * p(len)) % mod + ((j - 1) * (a[j] % mod)) % mod;
        ans %= mod;
    }
    cout << ans;
    return 0;
}
::::

::::::info[T5]{open}

P1100 高低位交换

::::info[题意] 给出一个小于 2^{32} 的非负整数。这个数可以用一个 32 位的二进制数表示(不足 32 位用 0 补足)。我们称这个二进制数的前 16 位为“高位”,后 16 位为“低位”。将它的高低位交换,我们可以得到一个新的数。试问这个新的数是多少(用十进制表示)。 :::: ::::info[思路] 利用位运算和 unsigned 类型,取其前十六位和后十六位,相加即可。 :::: ::::success[赛时得分&代码]

\color{green}{Accepted\not100tps}
#include <bits/stdc++.h>
#define u unsigned
using namespace std;
const int N = 2e5 + 5;
u x, y, z;
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> x;
    y = x >> 16;
    z = x << 16;
    cout << y + z;
    return 0;
}
::::