终于青名了。
赛时过了 五道题,还未补出 。
题:
是否能够防御住伤害,只需要防御大于伤害即可。
意思比较简单,按题面模拟即可,代码如下:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a, d;
inline void solve(){
cin >> a >> d;
if(a <= d) cout << "Yes";
else cout << "No";
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}题:
这个也比较简单,只要保证每一个渔夫说的和知道的对应的上即可。
代码如下:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 105;
int n, flag = 1, a[N], b[N];
inline void solve(){
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];
for(int i = 0; i < n; i++){
if(b[a[i] - 1] != i + 1){
flag = false;
break;
}
}
cout << (flag ? "Yes" : "No");
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}题:
我们可以先选择 块不同颜色的最大的,剩下的要最大的即可(赛时代码裂开了,吃了一发罚时)。
代码如下:
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5 + 5;
int n, k, m, c, v, ans;
bool vis[N];
vector<vector<int>> g;
priority_queue<int> pq;
priority_queue<PII> pq1;
unordered_map<int, vector<int>> mp;
inline void solve(){
cin >> n >> k >> m;
for(int i = 1; i <= n; i++){
cin >> c >> v;
mp[c].push_back(v);
}
for(auto& it : mp){
sort(it.second.rbegin(), it.second.rend());
g.push_back(it.second);
}
for(int i = 0; i < g.size(); i++) pq1.push({g[i][0], i});
for(int i = 1; i <= m; i++){
auto k = pq1.top();
pq1.pop();
ans += k.x, vis[k.y] = 1;
}
for(int i = 0; i < g.size(); i++){
if(vis[i]) for(int j = 1; j < g[i].size(); j++) pq.push(g[i][j]);
else for(int j = 0; j < g[i].size(); j++) pq.push(g[i][j]);
}
for(int i = 1; i <= k - m; i++){
ans += pq.top();
pq.pop();
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}题:
说实话,赛时觉得 是真的,这道题从题面上几乎和前缀和模板一模一样,可以先用二维前缀和预处理,剩下的按照题意模拟即可,不会超时。
代码如下:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 505;
int h, w, k, ans, arr[N][N];
string s;
vector<int> g;
unordered_map<int, int> mp;
inline int check(){
mp.clear();
mp[0] = 1;
int cnt = 0, res = 0;
for(int x : g) cnt += x, res += mp[cnt - k], mp[cnt]++;
return res;
}
inline void solve(){
cin >> h >> w >> k;
for(int i = 1; i <= h; i++){
cin >> s;
for(int j = 1; j <= w; j++) arr[i][j] = arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1] + s[j - 1] - '0';
}
for(int i = 1; i <= h; i++){
for(int j = i; j <= h; j++){
g.clear();
for(int k = 1; k <= w; k++){
int s = arr[j][k] - arr[i - 1][k] - arr[j][k - 1] + arr[i - 1][k - 1];
g.push_back(s);
}
ans += check();
}
}
cout << ans;
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}题:
这次的 没有之前那么难,而且很像之前某场 的 题,需要用一个全局变量来统计行与列之间的偏移量影响,其他和模板相同。
代码如下:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 5;
class BIT {
public :
int c[N];
inline int lowbit(int x){
return x & -x;
}
inline void add(int x, int v){
while(x < N){
c[x] += v;
x += lowbit(x);
}
}
inline int query(int x){
int res = 0;
while(x){
res += c[x];
x -= lowbit(x);
}
return res;
}
}row1, col1;
int n, q, op, x, sub, row[N], col[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> q;
for(int i = 1; i <= q; i++){
cin >> op >> x;
if(op == 1){
if(row[x]){
row1.add(row[x], -1);
sub -= (col1.query(N - 1) - col1.query(row[x] - 1));
}
row[x] = i;
row1.add(i, 1);
} else {
if(col[x]){
col1.add(col[x], -1);
sub -= row1.query(col[x]);
}
col[x] = i;
col1.add(i, 1);
sub += row1.query(i);
}
cout << row1.query(N - 1) * n - sub << '\n';
}
return 0;
}