search
HomeWeb Front-endHTML TutorialCF Question Collection PART 3 #262 div 2 D_html/css_WEB-ITnose

【#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:

  • for all x  the following inequality holds l?≤?x?≤?r;
  • 1?≤?|S|?≤?k;
  • lets denote the i-th element of the set S as si; value  must be as small as possible.
  • 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>
    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

    HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

    The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

    The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

    Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

    HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

    What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

    The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

    HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

    The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

    How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

    Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

    What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

    HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

    How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

    TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Hot Tools

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment

    VSCode Windows 64-bit Download

    VSCode Windows 64-bit Download

    A free and powerful IDE editor launched by Microsoft

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools