当前位置: 首页 > news >正文

Codeforces Round 1012 (Div. 2)

A. Treasure Hunt

注意深度是a.5米。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long longusing namespace std;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<long double,long double> PDD ;
const int N = 5010 , M = N * 2 , mod = 998244353 ;
int x , y , a ;void solve()
{cin >> x >> y >> a ;double u = a % (x + y) + 0.5 ;if(u > x) cout << "Yes\n" ;else cout << "No\n" ;
}
signed main()
{std::ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;int t = 1 ;cin >> t ;while (t --) solve() ;return 0;
}
B. Pushing Balls

如果某行或者某列是合法的,那么一定是从这行这列开始连着的1。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long longusing namespace std;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<long double,long double> PDD ;
const int N = 5010 , M = N * 2 , mod = 998244353 ;
int n , m ;
char a[55][55] ;
bool st[55][55] ;void solve()
{cin >> n >> m ;for(int i = 0 ; i < n ; i ++)cin >> a[i] ;memset(st , 0 , sizeof st) ;for(int i = 0 ; i < n ; i ++)if(a[i][0] == '1') {for(int j = 0 ; j < m ; j ++) {if(a[i][j] == '1') st[i][j] = 1 ;else break;}}for(int j = 0 ; j < m ; j ++)if(a[0][j] == '1') {for(int i = 0 ; i < n ; i ++) {if(a[i][j] == '1') st[i][j] = 1 ;else break;}}for(int i = 0 ; i < n ; i ++)for(int j = 0 ; j < m ; j ++)if(a[i][j] == '1' && !st[i][j]){cout << "NO\n" ;return;}cout << "YES\n" ;
}
signed main()
{std::ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;int t = 1 ;cin >> t ;while (t --) solve() ;return 0;
}
C. Dining Hall

a[i]==1时,这个人要选最近的没人坐的桌子,a[i]==0时,这个人要选最近的没人坐的椅子。

n最大为50000,也就是最多会坐50000个桌子。直接用BFS,维护桌子和椅子两个set。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long longusing namespace std;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<long double,long double> PDD ;
const int N = 50010 , M = N * 2 , mod = 998244353 ;
int n ;
int a[N] ;
int dx[4] = {0 , 0 , 1 , -1} , dy[4] = {-1 , 1 , 0 , 0};
struct node {int x  , y , d ;bool operator<(const node& o) const {if (d != o.d) return d > o.d;if (x != o.x) return x > o.x;return y > o.y;}
};void solve()
{cin >> n ;for(int i = 1 ; i <= n ; i ++) cin >> a[i] ;set<PII> st , used , u , v ;priority_queue<node> pu , pv;queue<node> q ;q.push({0 , 0 , 0}) ;while (q.size()) {auto t = q.front() ;q.pop() ;if(pu.size() >= n && pv.size() >= n) break;if(t.x % 3 && t.y % 3) {st.insert({t.x , t.y}) ;pv.push({t.x , t.y , t.d}) ;int ux = t.x / 3 , uy = t.y / 3 ;if(!used.count({ux , uy})) {used.insert({ux , uy}) ;pu.push({ux , uy , t.d}) ;}continue;}for(int i = 0 ; i < 4 ; i ++) {int fx = t.x + dx[i] , fy = t.y + dy[i] ;if(fx >= 0 && fy >= 0 && !st.count({fx , fy})) {q.push({fx , fy , t.d + 1}) ;st.insert({fx , fy}) ;}}}for(int i = 1 ; i <= n ; i ++) {if(a[i] == 0) {while (u.count({pu.top().x , pu.top().y})) pu.pop() ;auto t = pu.top() ;pu.pop() ;u.insert({t.x , t.y}) ;t.x *= 3 , t.y *= 3 ;cout << t.x + 1 << " " << t.y + 1 << "\n" ;v.insert({t.x + 1 , t.y + 1}) ;}else {while (v.count({pv.top().x , pv.top().y})) pv.pop() ;auto t = pv.top() ;pv.pop() ;v.insert({t.x , t.y}) ;cout << t.x << " " << t.y << "\n" ;u.insert({t.x / 3 , t.y / 3}) ;}}
}
signed main()
{std::ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;int t = 1 ;cin >> t ;while (t --) solve() ;return 0;
}
D. Simple Permutation

感觉这道题需要对脑电波,一开始猜的是“2 1 3 4 5 6 7...”,写了对拍到50都没有问题就交了。最后发现wa8。然后越想越不对,然后发现规律好像是"x , x - 1 , x + 1 , x + 2 , x + 3...",为了凑尽可能多对,x选择最接近n/2的质数。原理....等我找到了再补。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long longusing namespace std;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<long double,long double> PDD ;
const int N = 100010 , M = N * 2 , mod = 998244353 ;
int n ;
int p[N] , cnt , st[N] ;
bool used[N] ;void init() {for(int i = 2 ; i <= N - 10 ; i ++) {if(!st[i]) p[cnt ++] = i ;for(int j = 0 ; p[j] * i <= N - 10 ; j ++) {st[p[j] * i] = 1 ;if(i % p[j] == 0) break;}}
}
void solve()
{cin >> n ;for(int i = 1 ; i <= n ; i ++) used[i] = 0 ;int x = 2 ;for(int i = 0 ; i < cnt ; i ++){if(abs(p[i] - n / 2) < abs(x - n / 2))x = p[i] ;}vector<int> res ;res.push_back(x) ;used[x] = 1 ;for(int i = 1 ; i <= n / 2 ; i ++) {if(x - i >= 1) {res.push_back(x - i) ;used[x - i] = 1 ;}if(x + i <= n) {res.push_back(x + i) ;used[x + i] = 1 ;}}for(int i = 1 ; i <= n ; i ++) if(!used[i])res.push_back(i) ;for(int i = 0 ; i < res.size() ; i ++)cout << res[i] << " " ;cout << "\n" ;
}
signed main()
{std::ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;int t = 1 ;init() ;cin >> t ;while (t --) solve() ;return 0;
}

http://www.xdnf.cn/news/347887.html

相关文章:

  • MybatisPlus 发布 3.5.12 版本啦
  • 过曝区域信息补全
  • Python从入门到高手8.3节-元组的常用操作方法
  • 【战略合作】开封大学_阀门产业学院+智橙PLM
  • maven 依赖冲突异常分析
  • 17.thinkphp的分页功能
  • 开发者如何应对浏览器中的身份关联与反追踪问题?
  • 主成分分析(PCA)是什么?简易理解版
  • 使用Compose编排工具搭建Ghost博客系统
  • goner/otel 在Gone框架接入OpenTelemetry
  • [python] 函数1-函数基础
  • 软考职称政策再加码!已有多地发布通知!
  • SiC MOSFET同步Buck DC-DC变换器的宽频混合EMI滤波器设计
  • 【嵌入式开发-UART】
  • docker 安装 sqlserver2022 和注意点
  • 模拟散列表(算法题)
  • Vue3中emits和emit
  • Qwen3中的MoE是如何平衡专家负载的?
  • 跨线程和跨进程通信还有多种方式对比
  • JS 下载data:image/png;base64, 图片
  • 告别手动输入密码:基于SSHPass的自动化文件传输实践告别手动输入密码:基于SSHPass的自动化文件传输实践
  • Marin说PCB之器件的3D数模匹配失效案例
  • 在微程序控制器中,各概念之间的详细关系
  • IEEE出版|2025年物联网、数据科学与先进计算国际学术会议(IDSAC2025)
  • MyBatis 动态 SQL 完整笔记
  • 深泽多层电路在PCB行业中属于什么水平
  • laravel 使用异步队列,context带的上下文造成反序列化出问题
  • sql server限制用户只能访问特定表
  • PWN基础-ROP技术-ret2syscall-64位程序栈溢出利用
  • el-table合并单元