【#262 div 2 D. Little Victor and Set】
【原题】
D. Little Victor and Set
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties:
Help Victor find the described set.
Input
The first line contains three space-separated integers l,?r,?k (1?≤?l?≤?r?≤?1012; 1?≤?k?≤?min(106,?r?-?l?+?1)).
Output
Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order.
If there are multiple optimal sets, you can print any of them.
Sample test(s)
input
8 15 3
output
1210 11
input
8 30 7
output
0514 9 28 11 16
Note
Operation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation.
【题意】给定范围L和R,在这之间选P个不同的自然数,其中1
【分析】很显然的结论,K^(K+1)=1,其中K是偶数。当K>3时,我们可以选连续的4个自然数使异或和为0。(当然注意要特判R-L+1的大小)。当K=1时,就是L。当K=2时,显然只能构造异或为1的情况。
所有的推论都指向一个问题:当K=3的一般情况怎么做?
【题解】对于那个情况,我一直觉得能贪心构造,但是怎么也想不出简单易行且效率高的算法。
其实很简单。我们设L
在二进制中,异或和为0的情况是1,1,0或0,0,0。显然Z的第一位是1,然后X和Y是0。
因为是贪心,我们要尽量使Y靠近Z(因为如果Z符合范围,Y显然越大越好)。
那么第二位我们就让Y靠近Z。我们把Z那位设成0,X和Y都设成1,即如下形式:
110000000
101111111
011111111
当然脑补可能会萎...为了少特判,我在R-L+1小的时候直接暴力寻找。
【代码】
#include<cstdio>#include<algorithm>#include<iostream>#define E endl#define INF 999999999999999ll#define RE return 0using namespace std;typedef long long LL;LL len,sum,ans,C,wri[15],temp[15],i,S,L,R,k,x,z;inline void DFS(LL now,LL C,LL sum){ if (now==R+1) { if (sum>=ans||!C) return;len=C;ans=sum; for (int i=1;iR) return; DFS(now+1,C,sum);if (C+1>k) return; temp[C+1]=now;DFS(now+1,C+1,sum^now);}int main(){ cin>>L>>R>>k; if (L==R) {cout3) { S=(L&1)?L+1:L; cout=L) {cout <p class="sycode"> <br> </p> </iostream></algorithm></cstdio>

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。

htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代碼” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代碼”代碼“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract

HTML、CSS和JavaScript是Web開發的三大支柱。 1.HTML定義網頁結構,使用標籤如、等。 2.CSS控製網頁樣式,使用選擇器和屬性如color、font-size等。 3.JavaScript實現動態效果和交互,通過事件監聽和DOM操作。

HTML定義網頁結構,CSS負責樣式和佈局,JavaScript賦予動態交互。三者在網頁開發中各司其職,共同構建豐富多彩的網站。

HTML適合初學者學習,因為它簡單易學且能快速看到成果。 1)HTML的學習曲線平緩,易於上手。 2)只需掌握基本標籤即可開始創建網頁。 3)靈活性高,可與CSS和JavaScript結合使用。 4)豐富的學習資源和現代工具支持學習過程。

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

如何設計菜單中的虛線分割效果?在設計菜單時,菜名和價格的左右對齊通常不難實現,但中間的虛線或點如何...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

Dreamweaver Mac版
視覺化網頁開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

禪工作室 13.0.1
強大的PHP整合開發環境