Kickstart2018 Round (Practice ~ H)

Posted zhangwanying

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kickstart2018 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 
", 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("
");
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 }
View Code

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

 

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
", idx, ret);
35   }
36   return 0;
37 }
View Code

 

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)

 





















以上是关于Kickstart2018 Round (Practice ~ H)的主要内容,如果未能解决你的问题,请参考以下文章

Kickstart Round D 2018 B题 Paragliding

kickstart 2021 round A

Google Kickstart 2020 Round A: Plates Solution

kickstart_Round C 2020

2019 Google Kickstart Round H

2019 google kickstart round A