当前位置:网站首页>CAIP2021 初赛VP
CAIP2021 初赛VP
2022-07-07 21:50:00 【HeartFireY】
写点小题,放松一下。。。
A.7-1 懂的都懂
暴力打表,然后 O ( 1 ) O(1) O(1)回答询问即可。
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N];
map<int, bool> mp;
inline void solve(){
int n = 0, k = 0; cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
for(int k = j + 1; k <= n; k++){
for(int l = k + 1; l <= n; l++){
mp[a[i] + a[j] + a[k] + a[l]] = true;
}
}
}
}
for(int i = 1; i <= k; i++){
int m; cin >> m;
bool flag = true;
for(int i = 1; i <= m; i++){
int x; cin >> x;
if(!mp.count(x * 4)) flag = false;
}
if(flag) cout << "Yes\n";
else cout << "No\n";
}
}
signed main(){
solve();
return 0;
}
B.7-2 芬兰木棋
分象限和坐标轴按斜率排序,然后每个区域按顺序进行遍历,动态改变方向统计即可。
最大分数一定是所有木棋之和。可以assert检验答案对不对。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10, JD = 1e-5;
struct node{
int x, y, p;
double dis, k;
const bool operator< (const node & x) const {
return k < x.k || fabs(k - x.k) <= JD && dis < x.dis; }
}a[9][N];
int num[9] = {
0};
inline void solve(){
int n = 0; cin >> n;
//int sum = 0;
for(int i = 1; i <= n; i++){
int x, y, p; cin >> x >> y >> p; //sum += p;
double dis = pow((double)(x * x + y * y), 0.5);
double k = 1.0 * y / (1.0 * x);
if(x > 0 && y > 0) a[1][++num[1]] = {
x, y, p, dis, k};
if(x < 0 && y > 0) a[2][++num[2]] = {
x, y, p, dis, k};
if(x < 0 && y < 0) a[3][++num[3]] = {
x, y, p, dis, k};
if(x > 0 && y < 0) a[4][++num[4]] = {
x, y, p, dis, k};
if(x > 0 && y == 0) a[5][++num[5]] = {
x, y, p, dis, 0};
if(x < 0 && y == 0) a[6][++num[6]] = {
x, y, p, dis, 0};
if(x == 0 && y > 0) a[7][++num[7]] = {
x, y, p, dis, 0};
if(x == 0 && y < 0) a[8][++num[8]] = {
x, y, p, dis, 0};
}
for(int i = 1; i <= 8; i++) sort(a[i] + 1, a[i] + 1 + num[i]);
int cnt = 0, ans = 0, ansop = 0;
for(int x = 1; x <= 8; x++){
for(int i = 1; i <= num[x]; i++){
if(fabs(a[x][i].k - a[x][i - 1].k) <= JD){
if(a[x][i].p == 1) cnt++;
else{
if(cnt) ansop++, ans += cnt, cnt = 0;
ansop++, ans += a[x][i].p;
}
}
else{
if(cnt) ansop++, ans += cnt, cnt = 0;
if(a[x][i].p == 1) cnt++;
else ansop++, ans += a[x][i].p;
}
}
if(cnt) ansop++, ans += cnt, cnt = 0;
}
//assert(sum == ans);
cout << ans << ' ' << ansop << endl;
}
signed main(){
ios_base::sync_with_stdio(false);
solve();
return 0;
}
C.7-3 打怪升级
先跑Floyd再跑Dijkstra,代码没存…
属于是什么算法都能杂一起了。。。
D.7-4 疫情防控
典中典之并查集维护倒序加点
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
vector<int> g[N];
struct unionfind{
int par[N];
unionfind(int n) {
for(int i = 1; i <= n; i++) par[i] = i; }
int find(int u){
return (u == par[u] ? u : par[u] = find(par[u])); }
void merge(int u, int v){
int fau = find(u), fav = find(v);
if(fau != fav) par[fav] = u;
}
};
bitset<N> vis;
using pii = pair<int, int>;
struct query{
int c, q;
vector<pii> qu;
}a[N];
int ans[N];
inline void solve(){
int n, m, d; cin >> n >> m >> d;
for(int i = 1; i <= m; i++){
int u, v; cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
vis.reset();
for(int i = 1; i <= d; i++){
int c, q; cin >> c >> q;
vis[c] = true;
a[i] = {
c, q};
for(int j = 1; j <= q; j++){
int u, v; cin >> u >> v;
a[i].qu.emplace_back(pii{
u, v});
}
}
unionfind uf(n);
for(int i = 1; i <= n; i++){
if(!vis[i]){
for(auto v : g[i])
if(!vis[v]) uf.merge(i, v);
}
}
for(int i = d; i >= 1; i--){
int cnt = 0;
for(auto q : a[i].qu){
if(uf.find(q.first) != uf.find(q.second)) cnt++;
}
int u = a[i].c;
vis[u] = false;
for(auto v : g[u]){
if(!vis[v]) uf.merge(u, v);
}
ans[i] = cnt;
}
for(int i = 1; i <= d; i++) cout << ans[i] << endl;
}
signed main(){
solve();
return 0;
}
边栏推荐
- UE4_UE5蓝图command节点的使用(开启关闭屏幕响应-log-发布全屏显示)
- USB (十八)2022-04-17
- Wechat forum exchange applet system graduation design (3) background function
- Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- Specific method example of V20 frequency converter manual automatic switching (local remote switching)
- Interview questions: how to test app performance?
- Wechat forum exchange applet system graduation design completion (7) Interim inspection report
- 智慧社区和智慧城市之间有什么异同
- Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
猜你喜欢
Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
Software test classification
GEE(四):计算两个变量(影像)之间的相关性并绘制散点图
STL标准模板库(Standard Template Library)一周学习总结
Inftnews | the wide application of NFT technology and its existing problems
Line test - graphic reasoning - 1 - Chinese character class
微信论坛交流小程序系统毕业设计毕设(1)开发概要
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
V20变频器手自动切换(就地远程切换)的具体方法示例
Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
随机推荐
Circumvention Technology: Registry
iNFTnews | NFT技术的广泛应用及其存在的问题
Unity3D学习笔记5——创建子Mesh
[record of question brushing] 3 Longest substring without duplicate characters
Transform XL translation
FPGA基础篇目录
opencv scalar传入三个参数只能显示黑白灰问题解决
Install a new version of idea. Double click it to open it
Byte hexadecimal binary understanding
ArcGIS: field assignment_ The attribute table field calculator assigns values to fields based on conditions
七月第一周
智慧社區和智慧城市之間有什麼异同
智慧社区和智慧城市之间有什么异同
Wechat forum exchange applet system graduation design completion (6) opening defense ppt
Unity 动态合并网格纹理
Bit operation
Unity3D学习笔记6——GPU实例化(1)
Binary tree
Guessing game (read data from file)
CXF call reports an error. Could not find conduct initiator for address: