zoukankan      html  css  js  c++  java
  • 19-11-11-|

    前言不多说。

    就3天了,不如……

    24
    Miemeng 100
    00:00:02
    60
    00:00:03
    20
    00:00:04
    180
    00:00:04

    序:

    ——如何抢绿框?

    好,既然有人催我写,我就……写下。

    考试开始先打开三个题,然后下面有一个上传文件(其实提交框也挺好就是比较费心)

    然后二话不说先把考试文件夹里的三个文件目录搞进去(先创建一个空的)

    然后最后覆盖好就行了……

    然后最后看一下时间剩$10s$的时候先冷静一下,然后在预先准备好的三个页面里摁 end

    然后时间一到(最好先在比赛页刷新以保证正常提交)

    在第一个页面摁提交,然后 Ctrl + Tab 跳下一个,然后重复这个操作,

    如果足够冷静(我不够)就可以一秒内交三个代码辣,可以看我以前(很早)的赛事榜我一直一两秒交代码,

    就像写了脚本一样!

    ZJ:

    $mathsf{UOJ}$的$404$真好用

    倒计时了……

    于是有点紧张。

    不管了。

    开题。

    T1最大或??或?于是觉得是贪心,码了码,挂个对拍,发现有点伪,又重构了一下,挺好。

    T2,$mathsf{dpsb}$直面死亡$mathsf{dp}$,丢了一个背包上去。挂了一个对拍,非常兴奋(得60分真××兴奋)

    T3联合权值??

    看半天才看懂题,觉得可能可以使用 bitset ,但是只码了暴力。

    检查了文件名,调试语句等等,

    最后抢了一个绿框。

    TJ:

    T1:

    尽量使用与$B$位数相反的数。

    先使用一个最大的但比$B$小的$2^x-1$试一下(解决了$A leq 2^x-1$的全部)

    然后枚举$B$的某一位,并在后面贪心的填$1$

    我打的很丑所以复杂度是$Theta(log^2 N)$的。

    //maxor
    
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #define LL long long
    
    using namespace std;
    
    LL lowbit(LL x){
    	return x&(-x);
    }
    int main(){
    #ifndef LOCAL
    	freopen("maxor.in" ,"r",stdin);
    	freopen("maxor.out","w",stdout);
    #endif
    	ios_base::sync_with_stdio(false);
    	int T;
    	LL a,b;
    	cin>>T;
    	while(T--){
    		cin>>a>>b;
    		LL p=1,d=0;
    		if(lowbit(b+1)==b+1){
    			cout<<b<<endl;
    			goto nxt;
    		}
    		p=1;
    		while(p<=b)
    			p<<=1; p--;
    		if((p>>1)<=b && (p>>1)>=a){
    			cout<<((p>>1)|b)<<endl;
    			goto nxt;
    		}
    		for(LL i=60;i>=0;i--){
    			LL k=1ll<<i;
    			if(k&b){
    				d|=k;
    				LL l=d;
    //				cout<<d<<endl;
    				for(LL j=i-1;j>=0;j--){
    					LL t=1ll<<j;
    					if(!(t&b)){
    						if((l|t)<=b){
    							l|=t;
    //							cout<<l<<endl;
    						}
    					}
    				}
    				for(LL j=i-1;j>=0;j--){
    					LL t=1ll<<j;
    					if(t&b){
    						if((l|t)<=b){
    							l|=t;
    //							cout<<l<<endl;
    						}
    					}
    				}
    				if(l<=b && l>=a){
    					cout<<(l|b)<<endl;
    					goto nxt;
    				}
    			}
    		}
    		nxt:;
    	}
    }
    

    T2:

    考试的是dp

    看到$N leq 40$就是$Meet in the Middle$没错了

    于是我们将前面的一半和后面的一半处理出来,

    然后排序。

    二分答案。

    check的时候就直接枚举第一个序列,在第二个上跑单调指针就可以了。

    我用了 vector ,所以很慢,也不是很好处理,开两个数组其实更好。

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #define N 44
    #define M 1111111
    #define LL long long
    #define LF double
    
    using namespace std;
    
    int pn,arr[M];
    LL kth;
    LF lim;
    vector<LL> fr,ba;
    
    LL getval(LL id){
    	LL nans=0;
    	int j=(int)ba.size();
    //	cout<<ba.size()<<endl;
    	for(int i=0;i<(int)fr.size();i++){
    //		cout<<i<<" "<<j<<endl;
    //		cout<<fr[i]<<" "<<ba[j-1]<<endl;
    		while(j>0 && fr[i]+ba[j-1]>=id)j--;
    //		cout<<i<<"="<<j<<endl;
    //		cout<<"Del"<<ba.size()-j<<endl;
    		nans+=(int)ba.size()-j;
    	}
    //	cout<<id<<" "<<nans<<endl;
    	return nans;
    }
    int main(){
    #ifndef LOCAL
    	freopen("answer.in" ,"r",stdin);
    	freopen("answer.out","w",stdout);
    #endif
    	fr.reserve(1<<20);
    	ba.reserve(1<<20);
    	LF p=1;
    	ios_base::sync_with_stdio(false);
    	cin>>pn>>lim;
    	for(int i=1;i<=pn;i++){
    		cin>>arr[i];
    		p*=2;
    	}
    	kth=p-ceil(p*lim)+1;
    //	cout<<"Kth:"<<kth<<endl;
    	int lm=pn/2,rm=pn-lm;
    //	cout<<lm<<" "<<rm<<endl;
    	for(int s=0;s<1<<lm;s++){
    		LL va=0;
    		for(int i=1;i<=lm;i++){
    			int j=1<<(i-1);
    			if(s&j)va+=arr[i];
    		}
    		fr.push_back(va);
    	}
    	for(int s=0;s<1<<rm;s++){
    		LL va=0;
    		for(int i=1;i<=rm;i++){
    			int j=1<<(i-1);
    			if(s&j)va+=arr[i+lm];
    		}
    		ba.push_back(va);
    	}
    	sort(fr.begin(),fr.end());
    	sort(ba.begin(),ba.end());
    //	cout<<"Fr";for(auto i:fr)cout<<i<<" ";cout<<endl;
    //	cout<<"Ba";for(auto i:ba)cout<<i<<" ";cout<<endl;
    //	cout<<getval(2)<<endl;
    //	return 0;
    	LL l=0,r=40004000;
    	while(l<r){
    //		cout<<l<<" "<<r<<endl;
    		LL mid=(l+r+1)/2;
    		if(getval(mid)>=kth)
    			l=mid;
    		else
    			r=mid-1;
    	}
    	cout<<l<<endl;
    }
    

    T3

    贪心思想的dp

    先咕掉。

  • 相关阅读:
    1094. Car Pooling
    121. Best Time to Buy and Sell Stock
    58. Length of Last Word
    510. Inorder Successor in BST II
    198. House Robber
    57. Insert Interval
    15. 3Sum java solutions
    79. Word Search java solutions
    80. Remove Duplicates from Sorted Array II java solutions
    34. Search for a Range java solutions
  • 原文地址:https://www.cnblogs.com/kalginamiemeng/p/Exam20191111.html
Copyright © 2011-2022 走看看