当前位置:网站首页>2019 Shaanxi provincial competition j-bit operation + greed
2019 Shaanxi provincial competition j-bit operation + greed
2022-07-25 15:34:00 【Brother Tazi is here】
The main idea of the topic :
Here you are. n n n Intervals , You need to take a number from each interval . Make them rank with the largest .
Topic ideas :
Start from the high position and try to set 1. then check Every interval .
I turn the question into : Find less than R R R The largest of contains the current a n s ans ans Number of numbers X X X. then check It and L L L The size of the relationship .
So from Interval existence problem Turn into : The most valuable question . At this time, you can also be greedy .
In this way, I still take two log, You need to add pruning at two places , Last time from T Optimize to 277ms
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
const int maxn = 1e5 + 5;
const int maxb = 30;
const int mod = 1e9 + 7;
struct Node {
int first , second;
}a[maxn];
int bk[maxn] , u , v , tg[maxn];
inline int calc (int up , int x , int id){
if ((up & x) == x) return up; // prune 1: Prevent all 1( Or a lot 1) Of up appear
for (int i = maxb ; i >= 0 ; i--){
u = (up >> i) & 1;
v = (x >> i) & 1;
if (u == v) continue;
if ((x | (1 << i)) > up) {
// This situation means that this range will not be used in the future check 了 .
tg[id] = true;
return x | ((1 << i) - 1);
}
x |= (1 << i);
}
assert(x == up);
return x;
}
template <typename T>
void read(T & x){
x = 0;T f = 1;char ch = getchar();while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();}while (isdigit(ch)){
x = x * 10 + (ch ^ 48);ch = getchar();}x *= f;}
template <typename T>
void write(T x){
if(x < 0){
putchar('-');x = -x;}if (x > 9)write(x / 10);putchar(x % 10 + '0');}
int main()
{
int t; read(t);
while (t--){
int n ; read(n);
for (int i = 1 ; i <= n ; i++){
read(a[i].first);
read(a[i].second);
bk[i] = false;
}
int ans = 0;
for (int i = maxb ; i >= 0 ; i--){
ll tmp = ans | (1 << i);
bool ok = true;
for (int j = 1 ; j <= n && ok; j++){
if (bk[j]) continue;
if (tmp > a[j].second) ok = false;
tg[j] = false;
int mx = calc (a[j].second , tmp , j);
if (mx < a[j].first) ok = false;
}
if (ok) {
ans = tmp;
for (int j = 1 ; j <= n ; j++) if (tg[j]) bk[j] = true;
}
}
write(ans);
puts("");
}
return 0;
}
边栏推荐
- SQL cultivation manual from scratch - practical part
- PAT甲级1151 LCA in a Binary Tree (30 分)
- C#精挑整理知识要点11 委托和事件(建议收藏)
- MATLAB 如何生产随机复序列
- UIDocumentInteractionController UIDocumentPickerViewController
- 图论及概念
- C#精挑整理知识要点12 异常处理(建议收藏)
- Pat grade a 1151 LCA in a binary tree (30 points)
- Pytorch框架练习(基于Kaggle Titanic竞赛)
- 获取键盘按下的键位对应ask码
猜你喜欢

MySQL installation and configuration super detailed tutorial and simple database and table building method

matlab--CVX优化工具包安装

Pytorch学习笔记--常用函数总结3

p4552-差分

Idea护眼色设置

Graph theory and concept

Box avoiding mouse

ML - natural language processing - Introduction to natural language processing

matlab 如何保存所有运行后的数据

window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
随机推荐
<栈模拟递归>
Spark judges that DF is empty
Pat class a topic directory
为什么PrepareStatement性能更好更安全?
pageHelper不生效,sql没有自动加上limit
MySQL heap table_ MySQL memory table heap Usage Summary - Ninth Five Year Plan small pang
matlab--CVX优化工具包安装
C#精挑整理知识要点11 委托和事件(建议收藏)
ML - Speech - advanced speech model
SQL cultivation manual from scratch - practical part
Reflection - Notes
PageHelper does not take effect, and SQL does not automatically add limit
The difference between Apple buy in and apple pay
MySQL installation and configuration super detailed tutorial and simple database and table building method
Endnote 无法编辑range 解决
MATLAB 如何生产随机复序列
Pat grade a 1151 LCA in a binary tree (30 points)
死锁杂谈
Phased summary of the research and development of the "library management system -" borrowing and returning "module
CF365-E - Mishka and Divisors,数论+dp