2023 Shandong Provincial Collegiate Programming Contest

D. Fast and Fat(2023 ICPC 山东省赛)(二分+贪心检查)

题意:

        对于一个运动员 i ,他的速度是 vi,体重是 wi。如果运动员 j 的体重 wj <= wi,那么运动员 i 可以用原本的速度 vi 背着运动员 j 奔跑。如果 wj > wi,那么速度就变成了 vi - ( wi - wj ) (如果是负数,那么运动员 i 不能背着 j 奔跑)。

        给定一个T,代表有T组数据。每组数据第一行输入一个n,代表这个团队有n个人,后面n行,每行两个数vi,wi。运动员可以被背着跑,也不能不背着人跑。求这个团队奔跑起来后速度最慢的那个人  的速度最大值。

思路:

        我们可以发现,当vi+wi > vj+wj 时,i 一定可以背着 j 跑。

        考虑取速度最大值和最小值,然后不断二分找答案。

        在二分答案时,对于答案 x ,选出大于等于速度 x 的人当中 vi+wi 最高的几个人,分别去背着速度小于 x 的人当中 wi 最大的人奔跑。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
#define int long long
typedef pair<int, int>PII;
const int Max = 0x3f3f3f3f3f3f3f3f;
const int Min = -0x3f3f3f3f3f3f3f3f;
int n, m, k;
int T;
PII q1[N], q2[N];
queue<int>que, que2;
bool cmp(PII aa, PII bb)
{
    return aa.first+aa.second > bb.first+bb.second;
}
bool cmp2(PII aa, PII bb)
{
    return aa.second > bb.second;
}
int check(int x)
{
    while(que.size()) que.pop();   //多组输入,每次使用队列前都要清空
    while(que2.size()) que2.pop();
    //如果速度大于等于当前 x,那么将vi+wi从大到小存入队列(已经排完序了)
    for(int i = 0; i < n; i ++)
    {
        if(q1[i].first>=x) que.push(q1[i].first + q1[i].second - x);
    }
    //如果速度小于当前的 x, 那么将wi从大到小存入队列
    for(int i = 0; i < n; i ++)
    {
        if(q2[i].first<x) que2.push(q2[i].second);
    }
    //如果可以背人的人数小于需要被人背着的人数,直接false
    if(que.size() < que2.size()) return false;
    //一一对应,队列中vi+wi最大的去背着队列中wi最大的,队列中vi+wi第二大的去背着队列wi第二大的...
    while(que2.size())
    {
        if(que.front() < que2.front()) return false;
        que.pop(), que2.pop();
    }
    return true;
}
signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> T;
    while(T --)
    {
        int head = Min, tail = Max;
        cin >> n;
        for(int i = 0; i < n; i ++)
        {
            int x, y;
            cin >> x >> y;
            q1[i].first = q2[i].first = x;
            q1[i].second = q2[i].second = y;
            head = max(x, head);      //求出速度的最大值和最小值
            tail = min(x, tail);
        }
        sort(q1, q1+n, cmp); //pair 排序(根据vi+wi从大到小)
        sort(q2, q2+n, cmp2); // 根据wi从大到小排序
        // 二分答案
        while(tail < head)
        {
            int mid = head + tail + 1 >> 1;
            if(check(mid)) tail = mid;
            else head = mid - 1;
        }
        cout << head << "\n";
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Preface xv Introduction xvii Mathematical Notation xix Pseudo-Code xxi Contributors xxvi 1 2D GEOMETRY Useful 2D Geometry 3 Trigonometry Summary 12 Useful Trigonometry 13 Trigonometric Functions at Select Points 18 Triangles 20 Generating Random Points in Triangles (649) 24 Fast Line–Edge Intersections on a Uniform Grid (651) 29GRAPHICS GEMS I Edited by ANDREW S. GLASSNER viii CONTENTS Anti-Aliasing Summary 37 Area of Intersection: Circle and a Half-Plane 38 Area of Intersection: Circle and a Thick Line 40 Area of Intersection: Two Circles 43 Vertical Distance from a Point to a Line 47 A Fast 2D Point-on-Line Test (654)49 Fast Circle–Rectangle Intersection Checking (656)51 2 2D RENDERING Circles of Integral Radius on Integer Lattices 57 Nice Numbers for Graph Labels (657)61 Efficient Generation of Sampling Jitter Using Look-up Tables (660)64 Scan Conversion Summary 75 Fast Anti-Aliasing Polygon Scan Conversion (662)76 Generic Convex Polygon Scan Conversion and Clipping (667)84 ConcavePolygon Scan Conversion (681)87 Fast Scan Conversion of Arbitrary Polygons 92 Line-Drawing Summary 98 Digital Line Drawing (685)99 Symmetric Double Step Line Algorithm (686) 101 Rendering Anti-Aliased Lines (690) 105 An Algorithm for Filling in 2D Wide Line Bevel Joints 107 Rendering Fat Lines on a Raster Grid 114GRAPHICS GEMS I Edited by ANDREW S. GLASSNER ix CONTENTS Two-Dimensional Clipping: A Vector-Based Approach (694) 121 Periodic Tilings of the Plane on a Raster 129 3 IMAGE PROCESSING Anti-Aliasing Filters Summary 143 Convenient Anti-Aliasing Filters That Minimize “Bumpy” Sampling 144 Filters for Common Resampling Tasks 147 Smoothing Enlarged Monochrome Images 166 Median Finding on a 3 × 3 Grid (711) 171 Ordered Dithering (713) 176 A Fast Algorithm for General Raster Rotation 179 Useful 1-to-1 Pixel Transforms 196 Alpha Blending 210 4 FRAME BUFFER TECHNIQUES Frame Buffers and Color Maps 215 Reading a Write-Only Write Mask 219 A Digital “Dissolve” Effect (715) 221 Mapping RGB Triples onto Four Bits (718) 233 What Are the Coordinates of a Pixel? 246 Proper Treatment of Pixels as Integers (719) 249 Normal Coding 257 Recording Animation in Binary Order for Progressive Temporal Refinement (720) 265GRAPHICS GEMS I Edited by ANDREW S. GLASSNER x CONTENTS 1-to-1 Pixel Transforms Optimized through Color-Map Manipulation 270 A Seed Fill Algorithm (721) 275 Filling a Region in a Frame Buffer 278 Precalculating Addresses for Fast Fills, Circles, and Lines 285 A Simple Method for Color Quantization: Octree Quantization 287 5 3D GEOMETRY Useful 3D Geometry 297 An Efficient Bounding Sphere (723) 301 Intersection of Two Lines in Three-Space 304 Intersection of Three Planes 305 Mapping Summary 306 Digital Cartography for Computer Graphics 307 Albers Equal-Area Conic Map Projection. (726) 321 Boxes and Spheres Summary 326 Spheres-to-Voxels Conversion 327 A Simple Method for Box-Sphere Intersection Testing (730) 335 6 3D RENDERING 3D Grid Hashing Function (733) 343 Backface Culling 346GRAPHICS GEMS I Edited by ANDREW S. GLASSNER xi CONTENTS Fast Dot Products for Shading 348 Scanline Depth Gradient of a Z-Buffered Triangle 361 Simulating Fog and Haze 364 Interpretation of Texture Map Indices 366 Multidimensional Sum Tables 376 7 RAY TRACING A Simple Ray Rejection Test 385 Ray−Object Intersection Summary 387 Intersection of a Ray with a Sphere 388 An Efficient Ray−Polygon Intersection (735) 390 Fast Ray−Polygon Intersection 394 Fast Ray−Box Intersection (736) 395 Shadow Attenuation for Ray Tracing Transparent Objects 397 8 NUMERICAL AND PROGRAMMING TECHNIQUES Root Finding Summary 403 Cubic and Quartic Roots (738) 404 A Bézier Curve-Based Root-Finder (787) 408 Using Sturm Sequences to Bracket Real Roots of Polynomial Equations (743) 416 Distance Measures Summary 423GRAPHICS GEMS I Edited by ANDREW S. GLASSNER xii CONTENTS A High-Speed, Low Precision Square Root (756) 424 A Fast Approximation to the Hypotenuse (758) 427 A Fast Approximation to 3D Euclidean Distance 432 Full-Precision Constants 434 Converting between Bits and Digits 435 Storage-free Swapping 436 Generating Random Integers 438 Fast 2D−3D Rotation 440 Bit Patterns for Encoding Angles 442 Bit Interleaving for Quad- or Octrees (759) 443 A Fast HSL-to-RGB Transform (763) 448 9 MATRIX TECHNIQUES Matrix Identities 453 Rotation Matrix Methods Summary 455 Transforming Axes 456 Fast Matrix Multiplication 460 A Virtual Trackball 462 Matrix Orthogonalization (765) 464 Rotation Tools 465 Matrix Inversion (766) 470 Matrices and Transformations 472 Efficient Post-Concatenation of Transformation Matrices (770) 476GRAPHICS GEMS I Edited by ANDREW S. GLASSNER xiii CONTENTS 10 MODELING AND TRANSFORMATIONS Transformation Identities 485 Fixed-Point Trigonometry with CORDIC Iterations (773) 494 Using Quaternions for Coding 3D Transformations (775) 498 3D Viewing and Rotation Using Orthonormal Bases (778) 516 The Use of Coordinate Frames in Computer Graphics 522 Forms, Vectors, and Transforms (780) 533 Properties of Surface-Normal Transformations 539 Transforming Axis-Aligned Bounding Boxes (785) 548 Constructing Shapes Summary 551 Defining Surfaces from Sampled Data 552 Defining Surfaces from Contour Data 558 Computing Surface Normals for 3D Models 562 Calculation of Reference Frames along a Space Curve 567 11 CURVES AND SURFACES Planar Cubic Curves 575 Explicit Cubic Spline Interpolation Formulas 579 Fast Spline Drawing 585 Some Properties of Bézier Curves 587 Tutorial on Forward Differencing 594 Integration of Bernstein Basis Functions 604GRAPHICS GEMS I Edited by ANDREW S. GLASSNER xiv CONTENTS Solving the Nearest-Point-on-Curve Problem (787) 607 An Algorithm for Automatically Fitting Digitized Curves (797) 612 References 808 Index
WinHex is in its core a universal hexadecimal editor, particularly helpful in the realm of computer forensics, data recovery, low-level data processing, and IT security. An advanced tool for everyday and emergency use: inspect and edit all kinds of files, recover deleted files or lost data from hard drives with corrupt file systems or from digital camera cards. Features include (depending on the license type): Disk editor for hard disks, floppy disks, CD-ROM & DVD, ZIP, Smart Media, Compact Flash, ... Native support for FAT12/16/32, exFAT, NTFS, Ext2/3/4, CDFS, UDF Built-in interpretation of RAID systems and dynamic disks Various data recovery techniques RAM editor, providing access to physical RAM and other processes' virtual memory Data interpreter, knowing 20 data types Editing data structures using templates (e.g. to repair partition table/boot sector) Concatenating and splitting files, unifying and dividing odd and even bytes/words Analyzing and comparing files Particularly flexible search and replace functions Disk cloning (under DOS with X-Ways Replica) Drive images & backups (optionally compressed or split into 650 MB archives) Programming interface (API) and scripting 256-bit AES encryption, checksums, CRC32, hashes (MD5, SHA-1, ...) Erase (wipe) confidential files securely, hard drive cleansing to protect your privacy Import all clipboard formats, incl. ASCII hex values Convert between binary, hex ASCII, Intel Hex, and Motorola S Character sets: ANSI ASCII, IBM ASCII, EBCDIC, (Unicode) Instant window switching. Printing. Random-number generator. Supports files >4 GB. Very fast. Easy to use. Extensive online help. (more) Having all the bits and bytes in a computer at your fingertips has become a reality. Try before you buy, as long as you need, for free. Computer forensics edition of WinHex with even more features: X-Ways Forensics.
In this fully updated second edition of the highly acclaimed Managing Gigabytes, authors Witten, Moffat, and Bell continue to provide unparalleled coverage of state-of-the-art techniques for compressing and indexing data. Whatever your field, if you work with large quantities of information, this book is essential reading--an authoritative theoretical resource and a practical guide to meeting the toughest storage and access challenges. It covers the latest developments in compression and indexing and their application on the Web and in digital libraries. It also details dozens of powerful techniques supported by mg, the authors' own system for compressing, storing, and retrieving text, images, and textual images. mg's source code is freely available on the Web. * Up-to-date coverage of new text compression algorithms such as block sorting, approximate arithmetic coding, and fat Huffman coding * New sections on content-based index compression and distributed querying, with 2 new data structures for fast indexing * New coverage of image coding, including descriptions of de facto standards in use on the Web (GIF and PNG), information on CALIC, the new proposed JPEG Lossless standard, and JBIG2 * New information on the Internet and WWW, digital libraries, web search engines, and agent-based retrieval * Accompanied by a public domain system called MG which is a fully worked-out operational example of the advanced techniques developed and explained in the book * New appendix on an existing digital library system that uses the MG software Editorial Reviews Amazon.com Review Of all the tasks programmers are asked to perform, storing, compressing, and retrieving information are some of the most challenging--and critical to many applications. Managing Gigabytes: Compressing and Indexing Documents and Images is a treasure trove of theory, practical illustration, and general discussion in this fascinating technical subject. Ian Witten, Alistair Moffat, and Timothy Bell have
WinHex is in its core a universal hexadecimal editor, particularly helpful in the realm of computer forensics, data recovery, low-level data processing, and IT security. An advanced tool for everyday and emergency use: inspect and edit all kinds of files, recover deleted files or lost data from hard drives with corrupt file systems or from digital camera cards. Features include, depending on the license type (comparison): Disk editor for hard disks, floppy disks, CD-ROM & DVD, ZIP, Smart Media, Compact Flash, ... Native support for FAT12/16/32, exFAT, NTFS, Ext2/3/4, Next3®, CDFS, UDF Built-in interpretation of RAID systems and dynamic disks Various data recovery techniques RAM editor, providing access to physical RAM and other processes' virtual memory Data interpreter, knowing 20 data types Editing data structures using templates (e.g. to repair partition table/boot sector) Concatenating and splitting files, unifying and dividing odd and even bytes/words Analyzing and comparing files Particularly flexible search and replace functions Disk cloning (under DOS with X-Ways Replica) Drive images & backups (optionally compressed or split into 650 MB archives) Programming interface (API) and scripting 256-bit AES encryption, checksums, CRC32, hashes (MD5, SHA-1, ...) Erase (wipe) confidential files securely, hard drive cleansing to protect your privacy Import all clipboard formats, incl. ASCII hex values Convert between binary, hex ASCII, Intel Hex, and Motorola S Character sets: ANSI ASCII, IBM ASCII, EBCDIC, (Unicode) Instant window switching. Printing. Random-number generator. Supports files >4 GB. Very fast. Easy to use. Extensive online help. (more) Having all the bits and bytes in a computer at your fingertips has become a reality. Try before you buy, as long as you need, for free. Computer forensics edition of WinHex with even more features: X-Ways Forensics.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

21RGHLY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值