• 题意:有个\(n\)个公寓,每个公寓\(a_{i}\)代表着编号为\(1-a_{i}\)个房间,给你房间号,问它在第几栋公寓的第几个房间.

  • 题解:对每个公寓的房间号记一个前缀和,二分查找属于第几个公寓,然后求个差即可.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<long,long> PLL; int n,m;
    ll a[N],b[N]; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i){
    cin>>a[i];
    a[i]+=a[i-1];
    }
    for(int i=1;i<=m;++i) cin>>b[i]; for(int i=1;i<=m;++i){
    ll pos=lower_bound(a+1,a+1+n,b[i])-a;
    printf("%lld %lld\n",pos,b[i]-a[pos-1]);
    } return 0;
    }

Codeforces Round #481 (Div. 3) C. Letters (模拟,二分)的更多相关文章

  1. Codeforces Round #481 (Div. 3) C. Letters

    题目地址:http://codeforces.com/contest/978/problem/C 题解:有n个宿舍,每个宿舍人不一样多,有m封信,每封信送给对应的第m间房间,问这封信是给第几个宿舍,第 ...

  2. Codeforces Round #481 (Div. 3) F. Mentors (模拟,排序)

    题意:有一个长度为\(n\)的序列\(a\),求这个序列中有多少比\(a_{i}\)小的数,如果某两个位置上的数有矛盾,则不能算小. 题解:用\(pair\)来记录序列中元素的位置和大小,将他们升序排 ...

  3. Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)

    题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...

  4. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  7. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  8. Codeforces Round #327 (Div. 2) B. Rebranding 模拟

    B. Rebranding   The name of one small but proud corporation consists of n lowercase English letters. ...

  9. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

随机推荐

  1. MySQL select 查询之分组和过滤

    SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as alias2]][ ...

  2. 【Oracle】修改列的大小

    alter table 表名 modify column_name varchar2(32)  alter table 表名 modify (column_name1 varchar(20) defa ...

  3. ctfshow—web—web3

    打开靶机 提示是文件包含漏洞 测试成功 https://d7c9f3d7-64d2-4110-a14b-74c61f65893c.chall.ctf.show/?url=../../../../../ ...

  4. [APUE] 文件 I/O

    文件操作相关 API:open, read, write, lseek, close. 多进程共享文件的相关 API:dup, dup2, fcntl, sync, fsync, ioctl. 文件操 ...

  5. Redis中哈希分布不均匀该怎么办

    前言 Redis 是一个键值对数据库,其键是通过哈希进行存储的.整个 Redis 可以认为是一个外层哈希,之所以称为外层哈希,是因为 Redis 内部也提供了一种哈希类型,这个可以称之为内部哈希.当我 ...

  6. linux系统图形化管理工具

    webmin是一个非常好的图形化管理工具,提供了系统管理员对于linux系统的运维效率.对于那些记不住命令,新入门的新手真的是一个很好的工具呀,上图吧. 这是系统管理的首页,可以看到,CPU,内存.虚 ...

  7. 缓存淘汰算法 LRU 和 LFU

    LRU (Least Recently Used), 即最近最少使用用算法,是一种常见的 Cache 页面置换算法,有利于提高 Cache 命中率. LRU 的算法思想:对于每个页面,记录该页面自上一 ...

  8. window.open()打开新窗口教程

    使用 window 对象的 open() 方法可以打开一个新窗口.用法如下: window.open (URL, name, features, replace) 参数列表如下: URL:可选字符串, ...

  9. 三十二:WEB漏洞-文件操作之文件下载读取全解

    文件下载读取 原路,检测,利用,修复 利用 数据库配置文件下载或者读取后续 接口密钥信息文件下载或者读取后续 文件名,参数值,目录符号 read.xxx?filename= down.xxx?file ...

  10. zabbix客户端监控脚本shell

    zabbix客户端监控脚本shell #!/bin/sh sleep 3 zabbixdir=`pwd` zabbix_version=4.2.5 ###指定版本,最好和server端吻合版本,可以自 ...