1850F.We Were Both Children(Difficulty: 1300)

题目链接:

Problem - 1850F - Codeforces

 题目大致意思:

Mihai和Slavic正在观察一群青蛙,这些青蛙编号从1到n,初始位置都在点0处。青蛙i每跳一次可以跳跃ai单位长度。

每秒钟,青蛙i向前跳跃ai单位长度。在青蛙开始跳跃之前,Slavic和Mihai可以在一个坐标上放置一个陷阱,以便捕捉到所有将经过该坐标的青蛙。

然而,孩子们不能离开自己的家太远,所以他们只能在前n个点上放置陷阱(也就是坐标在1到n之间的点),并且孩子们不能在点0处放置陷阱,因为他们害怕青蛙。

你能帮助Slavic和Mihai找出使用一个陷阱可以捕捉到的青蛙的最大数量吗?

输入:
第一行输入一个整数t(1≤t≤100)——测试用例的数量。
每个测试用例的描述如下所示。

每个测试用例的第一行是一个整数n(1≤n≤2⋅10^5)——青蛙的数量,也就是Mihai和Slavic能够移动来放置陷阱的距离。
每个测试用例的第二行是n个整数a1,…,an(1≤ai≤10^9)——对应青蛙的跳跃长度。

保证所有测试用例中n的总和不超过2⋅10^5。

输出:
对于每个测试用例,输出一个整数——使用一个陷阱可以捕捉到的青蛙的最大数量。

 思路:

    先把青蛙的跳跃长度挨个输进frog数组,再在判断每一个跳跃长度有无超过n(超过就放弃,因为陷阱最远就到n),接着把小于n的跳跃步数作为下标,ma[frog[i]]++,记录每一种跳法的青蛙有几只(不用map因为这个跳跃步数不会超过数组的存储范围,数组就可以存,用map时间上会慢一点)。

    然后再挨个处理没一个位置上有几只青蛙可以跳到,从1开始,到j*j=i结束,如果i%j=0,在进行分支判断:

    一:如果j*j=i:则num+=ma[j]

    二:除一以外情况:num+=ma[j],num+=ma[i/j]

(我们可以理解为,a*b=i,也就是两个数的乘积为当前位置,因为我们只到j*j=i就结束了,所以有的乘积会大于j,例如:3*9=27,j到5就结束了)

    ans取最大的num,最后再输出ans。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int frog[N],ma[N];
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,ans=0,cnt=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            ma[i]=0;
            cin>>frog[i];
        }
        for(int i=1;i<=n;i++) if(frog[i]<=n) ma[frog[i]]++;
        for(int i=1;i<=n;i++){
            int num=0;
            for(int j=1;j*j<=i;j++){
                if(i%j==0){
                    if(j*j==i) num+=ma[j];
                    else num+=ma[j],num+=ma[i/j];
                }
            }
            ans=max(ans,num);
        }
        cout<<ans<<"\n";
    }
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Wireless sensor networks (WSNs) have attracted a wide range of disciplines where close interactions with the physical world are essential. The distributed sensing capabilities and the ease of deployment provided by a wireless communication paradigm make WSNs an important component of our daily lives. By providing distributed, real-time information from the physical world, WSNs extend the reach of current cyber infrastructures to the physical world. WSNs consist of tiny sensor nodes, which act as both data generators and network relays. Each node consists of sensor(s), a microprocessor, and a transceiver. Through the wide range of sensors available for tight integration, capturing data from a physical phenomenon becomes standard. Through on-board microprocessors, sensor nodes can be programmed to accomplish complex tasks rather than transmit only what they observe. The transceiver provides wireless connectivity to communicate the observed phenomena of interest. Sensor nodes are generally stationary and are powered by limited capacity batteries. Therefore, although the locations of the nodes do not change, the network topology dynamically changes due to the power management activities of the sensor nodes. To save energy, nodes aggressively switch their transceivers off and essentially become disconnected from the network. In this dynamic environment, it is a major challenge to provide connectivity of the network while minimizing the energy consumption. The energy-efficient operation of WSNs, however, provides significantly long lifetimes that surpass any system that relies on batteries. In March 2002, our survey paper “Wireless sensor networks: A survey” appeared in the Elsevier jour- nal Computer Networks, with a much shorter and concise version appearing in IEEE Communications Magazine in August 2002. Over the years, both of these papers were among the top 10 downloaded papers from Elsevier and IEEE Communication Society (ComSoc) journals with over 8000 citations in total. 1 Since then, the research on the unique challenges of WSNs has accelerated significantly. In the last decade, promising results have been obtained through these research activities, which have enabled the development and manufacture of sophisticated products. This, as a result, eventually created a brand- new market powered by the WSN phenomenon. Throughout these years, the deployment of WSNs has become a reality. Consequently, the research community has gained significant experience through these deployments. Furthermore, many researchers are currently engaged in developing solutions that address the unique challenges of the present WSNs and envision new WSNs such as wireless underwater and underground sensor networks. We have contributed to this research over the years through numerous articles and four additional survey/roadmap papers on wireless sensor actor networks, underwater acoustic networks, wireless underground sensor networks, and wireless multimedia sensor networks which were published in different years within the last decade. In summer 2003, we started to work on our second survey paper on WSNs to revisit the state-of-the- art solutions since the dawn of this phenomenon. The large volume of work and the interest in both academia and industry have motivated us to significantly enhance this survey to create this book, which is targeted at teaching graduate students, stimulating them for new research ideas, as well as providing academic and industry professionals with a thorough overview and in-depth understanding of the state- of-the-art in wireless sensor networking and how they can develop new ideas to advance this technology as well as support emerging applications and services. The book provides a comprehensive coverage of 1 According to Google Scholar as of October 2009.xx Preface the present research on WSNs as well as their applications and their improvements in numerous fields. This book covers several major research results including the authors’ own contributions as well as all standardization committee decisions in a cohesive and unified form. Due to the sheer amount of work that has been published over the last decade, obviously it is not possible to cover every single solution and any lack thereof is unintentional. The contents of the book mainly follow the TCP/IP stack starting from the physical layer and covering each protocol layer in detail. Moreover, cross-layer solutions as well as services such as synchronization, localization, and topology control are discussed in detail. Special cases of WSNs are also introduced. Functionalities and existing protocols and algorithms are covered in depth. The aim is to teach the readers what already exists and how these networks can further be improved and advanced by pointing out grand research challenges in the final chapter of the book. Chapter 1 is a comprehensive introduction to WSNs, including sensor platforms and network architectures. Chapter 2 summarizes the existing applications of WSNs ranging from military solutions to home applications. Chapter 3 provides a comprehensive coverage of the characteristics, critical design factors, and constraints of WSNs. Chapter 4 studies the physical layer of WSNs, including physical layer technologies, wireless communication characteristics, and existing standards at the WSN physical layer. Chapter 5 presents various medium access control (MAC) protocols for WSNs, with a special focus on the basic carrier sense multiple access with collision avoidance (CSMA/CA) techniques used extensively at this layer, as well as distinct solutions ranging from CSMA/CA variants, time division multiple access (TDMA)-based MAC, and their hybrid counterparts. Chapter 6 focuses on error control techniques in WSNs as well as their impact on energy-efficient communication. Along with Chapter 5, these two chapters provide a comprehensive evaluation of the link layer in WSNs. Chapter 7 is dedicated to routing protocols for WSNs. The extensive number of solutions at this layer are studied in four main classes: data-centric, hierarchical, geographical, and quality of service (QoS)- based routing protocols. Chapter 8 firstly introduces the challenges of transport layer solutions and then describes the protocols. Chapter 9 introduces the cross-layer interactions between each layer and their impacts on communication performance. Moreover, cross-layer communication approaches are explained in detail. Chapter 10 discusses time synchronization challenges and several approaches that have been designed to address these challenges. Chapter 11 presents the challenges for localization and studies them in three classes: ranging techniques, range-based localization protocols, and range- free localization protocols. Chapter 12 is organized to capture the topology management solutions in WSNs. More specifically, deployment, power control, activity, scheduling, and clustering solutions are explained. Chapter 13 introduces the concept of wireless sensor–actor networks (WSANs) and their characteristics. In particular, the coordination issues between sensors and actors as well as between different actors are highlighted along with suitable solutions. Moreover, the communication issues in WSANs are discussed. Chapter 14 presents wireless multimedia sensor networks (WMSNs) along with their challenges and various architectures. In addition, the existing multimedia sensor network platforms are introduced, and the protocols are described in the various layers following the general structure of the book. Chapter 15 is dedicated to underwater wireless sensor networks (UWSNs) with a major focus on the impacts of the underwater environment. The basics of underwater acoustic propagation are studied and the corresponding solutions at each layer of the protocol stack are summarized. Chapter 16 introduces wireless underground sensor networks (WUSNs) and various applications for these networks. In particular, WUSNs in soil and WUSNs in mines and tunnels are described. The channel properties in both these cases are studied. Furthermore, the existing challenges in the communication layers are described. Finally, Chapter 17 discusses the grand challenges that still exist for the proliferation of WSNs. It is a major task and challenge to produce a textbook. Although usually the authors carry the major burden, there are several other key people involved in publishing the book. Our foremost thanks go to Birgit Gruber from John Wiley & Sons who initiated the entire idea of producing this book. Tiina Ruonamaa, Sarah Tilley, and Anna Smart at John Wiley & Sons have been incredibly helpful, persistent,Preface xxi and patient. Their assistance, ideas, dedication, and support for the creation of this book will always be greatly appreciated. We also thank several individuals who indirectly or directly contributed to our book. In particular, our sincere thanks go to Özgur B. Akan, Tommaso Melodia, Dario Pompili, Weilian Su, Eylem Ekici, Cagri Gungor, Kaushik R. Chowdhury, Xin Dong, and Agnelo R. Silva for their help. I (MCV) would like to specifically thank the numerous professors who have inspired me throughout my education in both Bilkent University, Ankara, Turkey and Georgia Institute of Technology, Atlanta, GA. I would like to thank my colleagues and friends at the University of Nebraska–Lincoln and the Department of Computer Science and Engineering for the environment they created during the development of this book. I am especially thankful to my PhD advisor, Professor Ian F. Akyildiz, who introduced me to the challenges of WSNs. I wholeheartedly thank him for his strong guidance, friendship, and trust during my PhD as well as my career thereafter. I would also like to express my deep appreciation to my wife, Demet, for her love, exceptional support, constructive critiques, and her sacrifices that made the creation of this book possible. I am thankful to my mom, Ayla, for the love, support, and encouragement that only a mother can provide. Finally, this book is dedicated to the loving memory of my dad, Mehmet Vuran (or Hem¸serim as we used to call each other). He was the greatest driving force for the realization of this book as well as many other accomplishments in my life. I (IFA) would like to specifically thank my wife and children for their support throughout all these years. Without their continuous love, understanding, and tolerance, none of these could have been achieved. Also my past and present PhD students, who became part of my family over the last 25 years, deserve the highest and sincerest thanks for being in my life and letting me enjoy the research to the fullest with them. The feeling of seeing how they developed in their careers over the years is indescribable and one of the best satisfactions in my life. Their research results contributed a great deal to the contents of this book as well. Ian F. Akyildiz and Mehmet Can Vuran
Version 1.7 ----------- - ADD: Delphi/CBuilder 10.2 Tokyo now supported. - ADD: Delphi/CBuilder 10.1 Berlin now supported. - ADD: Delphi/CBuilder 10 Seattle now supported. - ADD: Delphi/CBuilder XE8 now supported. - ADD: Delphi/CBuilder XE7 now supported. - ADD: Delphi/CBuilder XE6 now supported. - ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now supported. - ADD: Delphi/CBuilder 2010 now supported. - ADD: Delphi/CBuilder 2009 now supported. - ADD: New demo project FlexCADImport. - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond docuemnt wasn't filled when TFlexPanel.DocClipping=True. - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object. - FIX: The result rectangle incorrectly calculated in the TFlexText.GetRefreshRect method. - FIX: Added FPaintCache.rcPaint cleanup in the TFlexPanel.WMPaint method. Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache field moved in the protected class section. Added rcPaint field in FPaintCache that represents drawing rectangle. - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used instead). - FIX: The TFlexRegularPolygon object clones incorrectly drawed in case when TFlexRegularPolygon have alternative brush (gradient, texture). - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFle

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值