【Kickstart】2018 Round (Practice ~ H)

Practice Round

Problem A GBus count (9pt/15pt) (2019年1月14日,kickstart群每日一题)

题意:有一条笔直的大路,上面有城市编号从 1 开始从左到右一次排列。上面有 N 个 GBuses, 每一个 bus[i] 连接 A[i]  到 B[i] 两个地点(包含这两个地方)。我们想要求 P 个城市,每个城市经过的公交车数量。

输入输出 和 数据规模 如下:

There exist some cities that are built along a straight road. The cities are numbered 1, 2, 3... from left to right.
There are N GBuses that operate along this road. For each GBus, we know the range of cities that it serves: the i-th gBus serves the cities with numbers between Ai and Bi, inclusive.
We are interested in a particular subset of P cities. For each of those cities, we need to find out how many GBuses serve that particular city.
Input
The first line of the input gives the number of test cases, T. Then, T test cases follow; each case is separated from the next by one blank line. (Notice that this is unusual for Kickstart data sets.)
In each test case:
The first line contains one integer N: the number of GBuses.
The second line contains 2N integers representing the ranges of cities that the buses serve, in the form A1 B1 A2 B2 A3 B3 ... AN BN. That is, the first GBus serves the cities numbered from A1 to B1 (inclusive), and so on.
The third line contains one integer P: the number of cities we are interested in, as described above. (Note that this is not necessarily the same as the total number of cities in the problem, which is not given.)
Finally, there are P more lines; the i-th of these contains the number Ci of a city we are interested in.
Output
For each test case, output one line containing Case #x: y, where x is the number of the test case (starting from 1), and y is a list of P integers, in which the i-th integer is the number of GBuses that serve city Ci.

Limits
1 ≤ T ≤ 10.
Small dataset
1 ≤ N ≤ 50
1 ≤ Ai ≤ 500, for all i.
1 ≤ Bi ≤ 500, for all i.
1 ≤ Ci ≤ 500, for all i.
1 ≤ P ≤ 50.
Large dataset
1 ≤ N ≤ 500.
1 ≤ Ai ≤ 5000, for all i.
1 ≤ Bi ≤ 5000, for all i.
1 ≤ Ci ≤ 5000, for all i.
1 ≤ P ≤ 500.

题解:我们只需要把每个bus的起点和终点读进来,然后对于每一个城市,都去每个bus的区间里面查这个城市是不是在这个bus区间里面,是的话就加一。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <vector>
 5 #include <map>
 6 #include <set>
 7
 8 using namespace std;
 9
10 void print(vector<pair<int, int>>& bus) {
11   for (int i = 0; i < bus.size(); ++i) {
12     printf("%d -> %d \n", bus[i].first, bus[i].second);
13   }
14 }
15 void solve(const int id) {
16   int n, p;
17   cin >> n;
18   vector<pair<int, int>> bus(n);
19   for (int i = 0; i < n; ++i) {
20     int s, e;
21     cin >> s >> e;
22     if (s > e) {
23       swap(s, e);
24     }
25     bus[i] = make_pair(s, e);
26   }
27 // print(bus);
28   cin >> p;
29   vector<int> ans(p, 0);
30   for (int i = 0; i < p; ++i) {
31     int city;
32     cin >> city;
33     for (auto b : bus) {
34       if (city >= b.first && city <= b.second) {
35         ans[i]++;
36       }
37     }
38   }
39   printf("Case #%d:", id);
40   for (auto e : ans) {
41     printf(" %d", e);
42   }
43   printf("\n");
44   return;
45 }
46 int main () {
47   int t;
48   cin >> t;
49   for (int idx = 1; idx <= t; ++idx) {
50     solve(idx);
51   }
52   return 0;
53 }

 总监说线段树,我下周学习一下线段树==

Problem B Googol String (7pt/12pt) (2019年1月15日, kickstart群每日一题)

给了一个非常长的字符串,有一定的生成规则,问字符串的第 K 个字母是啥。

A "0/1 string" is a string in which every character is either 0 or 1. There are two operations that can be performed on a 0/1 string:

  • switch: Every 0 becomes 1 and every 1 becomes 0. For example, "100" becomes "011".
  • reverse: The string is reversed. For example, "100" becomes "001".

Consider this infinite sequence of 0/1 strings:
S0 = ""
S1 = "0"
S2 = "001"
S3 = "0010011"
S4 = "001001100011011"
...
SN = SN-1 + "0" + switch(reverse(SN-1)).
You need to figure out the Kth character of Sgoogol, where googol = 10^100.
Input
The first line of the input gives the number of test cases, T. Each of the next T lines contains a number K.
Output
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the Kth character of Sgoogol.
Limits
1 ≤ T ≤ 100.
Small dataset
1 ≤ K ≤ 10^5.
Large dataset
1 ≤ K ≤ 10^18.

题解:小数据暴力可以解出来,大数据不行。大数据看了下答案学习了一下。整个字符串呈中心对称(字符串数组 1-based),2^k 的位置肯定是 0, 左右子串中心对称,并且需要 switch 0,1. 代码怎么写需要复习,一开始还没搞明白怎么写。明天复习。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <vector>
 5 #include <map>
 6 #include <set>
 7
 8 using namespace std;
 9 typedef long long ll;
10
11 int bst(ll k, int x);
12 int solve() {
13   ll k;
14   scanf("%lld", &k);
15   return bst(k, 60); //2^60 > 1e18
16 }
17 // string is 1-based.
18 int bst(ll k, int x) {
19   ll sz = 1LL << x;
20   if (k == sz) { return 0; }
21   if (k < sz) {  //left substr
22     return bst(k, x-1);
23   }
24   if (k > sz) { // right substr
25     return 1 ^ bst(sz - (k - sz), x-1); //return 1 - bst(sz - (k - sz), x-1);
26   }
27   return -1;
28 }
29 int main () {
30   int t;
31   cin >> t;
32   for (int idx = 1; idx <= t; ++idx) {
33     int ret = solve();
34     printf("Case #%d: %d\n", idx, ret);
35   }
36   return 0;
37 }

Problem C Sort a scarmbled itinerary (11pt/15pt)

Problem D Sums of Sums (8pt/28pt)

Round A

Problem A Even Digits (8pt/15pt)

Problem B Lucky Dip (10pt/19pt)

Problem C Scrambled Words (18pt/30pt)

Round B

Problem A No Line (7pt/13pt)

Problem B Sherlock and Bit Strings (11pt/26pt)

Problem C King‘s Circle (16pt/27pt)

Round C

Problem A Planet Distance (10pt/15pt)

Problem B Fairies and Witches (15pt/21pt)

Problem C Kickstart Alarm (13pt/26pt)

Round D

Problem A Candies (10pt/15pt)

Problem B Paragliding (8pt/22pt)

Problem C Funniest Word Search (15pt/30pt)

Round E

Problem A Yogurt (10pt/10pt)

Problem B Milk Tea (10pt/10pt)

Problem C Board Game (10pt/10pt)

Round F

Problem A Common Anagrams (8pt/10pt)

Problem B Specializing Villages (12pt/18pt)

Problem C Palindromic Sequence (22pt/30pt)

Round G

Problem A Product Triplets (5pt/12pt)

Problem B Combining Classes (16pt/21pt)

Problem C Cave Escape (19pt/27pt)

Round H

Problem A Big Buttons (9pt/13pt)

Problem B Mural (14pt/19pt)

Problem C Let Me Count The Ways (20pt/25pt)

原文地址:https://www.cnblogs.com/zhangwanying/p/10154583.html

时间: 2024-10-31 20:56:22

【Kickstart】2018 Round (Practice ~ H)的相关文章

【排序】【规律】Codeforces Round #254 (Div. 2) - D. Rooter&#39;s Song

D. DZY Loves FFT Source http://codeforces.com/contest/445/problem/D Description Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w?×?h, represented by a re

【流媒体】 Android 实时视频编码—H.264硬编码

[流媒體] Android 实时视频编码—H.264硬编码 SkySeraph Apr 4th 2012 Email:[email protected].com 1  硬编码 & 软编码 硬编码:通过调用Android系统自带的Camera录制视频,实际上是调用了底层的高清编码硬件模块,也即显卡,不使用CPU,速度快 软编码:使用CPU进行编码,如常见C/C++代码,一般编译生成的二进制都是的,速度相对较慢.例如使用Android NDK编译H264生成so库,编写jni接口,再使用java调用

【读书】2018

<旁观者> [书名]:<旁观者> [作者]:彼得·德鲁克 [时间]:2018年1月22日 [读感]:我们日常都会提到“多站在对方的角度”去思考,我觉得这里其实有一个非常重要的前提,那就是我们要有足够高的高度能站在对方思考.所以说,如果达到换位思考能力的人,他真实一个非常了不起的人,就像德鲁克.最重要的是,德鲁克通过他的旁观者角色带给了我前所未有的高度提升. <经济人的末日> [书名]:<经济人的末日> [作者]:彼得·德鲁克 [时间]:2018年3月7日 [

【CF】codeforces round 369(div2)

*明早起来再贴代码 A [题意] 给定n*5的方格 将横向的相邻两个变成+输出   [题解] ...   B [题意] 一个n*n的正整数矩阵,有且仅有一个数为0 ,在这个位置填上一个数,使得每一列的和 每一行的和 两条对角线各自的和都相等 输出这个数   [题解]sb题.暴力一下.注意细节,否则你就像这样 (不是本人   C [题意] 一排点,用1~n表示,熊孩子要给这些点上色.最初每个点的颜色为ci.一共有m种颜色,如果ci=0表示这个点最初无色. 熊孩子们需要给最初为无色的点涂上色,往第i

【BC】BestCoder Round#86小结

1001 [题意] 给定一个长度为n(n<=100000)的正整数序列,给出m(m<=100000)个子集合和的记录,问哪些一定比正确的记录多了 [题解] 对正整数序列求和,记录比和大的一定记录多了 HackPoint:sum要开long long int v[100005]; int main(){ int T=gi; while(T--){ int n,m;n=gi,m=gi;ll sum=0; FOR1(i,n)v[i]=gi,sum+=v[i]; FOR1(i,m){ ll p;sca

【GDOI】2018题目及题解(未写完)

我的游记:https://www.cnblogs.com/huangzihaoal/p/11154228.html DAY1 题目 T1 农场 [题目描述] [输入] 第一行,一个整数n. 第二行,n个整数\(a_i\) [输出] 一个数,最多可以分成几块. [样例输入] 6 1 1 2 1 2 1 [样例输出] 2 [数据范围限制] T2 密码锁 [题目描述] [输入] 输入文件共两行,第一行有两个数字n,m,第二行为一个长为n的数组\(a_1,a_2, ... ,a_n\) [输出] 输出文

【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration

题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命名为X+1~X+Y. 先把未使用的名字压进两个栈. 分为三轮:第一轮把占用了对方名字的样例数据以及占用了对方名字的大数据放进两个队列,然后不断反复尝试对这两个队列进行出队操作,每次将占用对方名字的改成一个未被使用的正确名字(从栈里取出),然后将占用的名字压进另一个栈.由于每个数据只会出队一次,所以是

【枚举】【二分】【推导】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担给它们,要求每台服务器承担的资源需求不超过其所能提供的资源需求.给定一种合法的方案,每台服务器要么没有被分配给任何一个服务,或者被分配给其中一个服务. 对服务器按能提供的资源从小到大排序.枚举给S1分配的服务器数量i,然后在a数组中二分,就可以得到给S1提供的是哪i台服务器,它们占据了a数组中连续的

【codeforces】Codeforces Round #277 (Div. 2) 解读

门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; typedef long long LL ; LL n ; int main () { while ( ~scanf ( "%I64d" , &n )