当前位置:网站首页>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;
}
边栏推荐
- The development summary of the function of fast playback of audio and video in any format on the web page.
- BPSK调制系统MATLAB仿真实现(1)
- wait()和sleep()的区别理解
- Games101 review: linear algebra
- 分布式 | 实战:将业务从 MyCAT 平滑迁移到 dble
- Week303 of leetcode
- Spark SQL common time functions
- Seata中jdbc下只有一个lib嘛?
- MATLAB 如何生产随机复序列
- 获取键盘按下的键位对应ask码
猜你喜欢

matlab 优化工具 manopt 安装

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

Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)

Idea remotely submits spark tasks to the yarn cluster

GAMES101复习:三维变换

为什么PrepareStatement性能更好更安全?

MySQL transactions and mvcc

ML - 图像 - 深度学习和卷积神经网络

Delayed loading source code analysis:

Brain racking CPU context switching
随机推荐
MySQL heap table_ MySQL memory table heap Usage Summary - Ninth Five Year Plan small pang
window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
BPSK调制系统MATLAB仿真实现(1)
MATLAB读取显示图像时数据格式转换原因
Graph theory and concept
matlab---错误使用 var 数据类型无效。第一个输入参数必须为单精度值或双精度值
How to update JSON values in the database?
MATLAB 如何生产随机复序列
带你创建你的第一个C#程序(建议收藏)
ML - 语音 - 语音处理介绍
伤透脑筋的CPU 上下文切换
Phased summary of the research and development of the "library management system -" borrowing and returning "module
C#精挑整理知识要点9 集合2(建议收藏)
本地缓存--Ehcache
ML - 图像 - 深度学习和卷积神经网络
matlab randint,Matlab的randint函数用法「建议收藏」
分布式原理 - 什么是分布式系统
UIDocumentInteractionController UIDocumentPickerViewController
数据系统分区设计 - 分区再平衡(rebalancing)
Xcode添加mobileprovision证书文件报错:Xcode encountered an error