8.24-河西校区
T1
T640711 快递费用
题意
某邮寄公司按物品重量和目的地区域收费。
重量标准为:
不足 克 元,超过 克的,超重的部分按每 克加收费用。超出的重量不足 克的,按 克计算。
目的地区域标准: 区域 :每超重 克加收 元;
区域 :每超重 克加收 元;
区域 :每超重 克加收 元;
区域 :每超重 克加收 元;
区域 :每超重 克加收 元。
思路
按照题意模拟即可。
赛时代码&得分
#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;
}T2
T638889 石头布没有剪刀
题意
你和对手都只有两种出拳方式:石头 g 和布p,规则一样,赢了得一分,平局不得分,输了减一分。
现给你对手的出拳方式,在对于任意位置 满足你出过的石头的次数大于你出过的布的次数时,输出你能得到的最大分数。
赛时得分
思路
能出布就出布。
正解
#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;
}T3
T644252 篝火问题
题意
在一个二维平面上,原点存在一个篝火,会不停地在这一格产生烟雾。每秒都有风把烟雾吹向四方,风速一秒一格。
求在观测点 是否有烟雾。
赛时得分
根本没写。
思路
由于一个一个模拟烟雾移动太费时间,故利用题目所说“求观测点是否有烟雾”和相对运动,只移动篝火和人。
正解
#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;
}T4
T639146 落落的去的数学问题3
题意
定义 如下:
将 的十进制表示分别作为字符串解释,并按顺序连接,得到字符串 。将 作为十进制整数解释,其值即为 。
给定一个长度为 的正整数序列 。请计算下式的值对 取模的结果:
赛时得分
暴力。
思路
对于每一个 ,前缀和预处理所有 之前的 ,统一做乘法运算。
正解
#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;
}T5
P1100 高低位交换
题意
给出一个小于 的非负整数。这个数可以用一个 位的二进制数表示(不足 位用 补足)。我们称这个二进制数的前 位为“高位”,后 位为“低位”。将它的高低位交换,我们可以得到一个新的数。试问这个新的数是多少(用十进制表示)。
思路
利用位运算和 unsigned 类型,取其前十六位和后十六位,相加即可。
赛时得分&代码
#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;
}