https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff08/0000000000386d5c (kick start上网方式需百度)

(第一题ac,第二题ac,第三题,小数据集能ac,第四题,小数据集能ac)

第一题:

大致意思就是要找峰值点(第一,必须严格大于前面所有值,第二,要么是结尾值,要么必须满足比后一位严格大),基础题,略

Problem

Isyana is given the number of visitors at her local theme park on N consecutive days. The number of visitors on the i-th day is Vi. A day is record breaking if it satisfies both of the following conditions:

  • The number of visitors on the day is strictly larger than the number of visitors on each of the previous days.
  • Either it is the last day, or the number of visitors on the day is strictly larger than the number of visitors on the following day.

Note that the very first day could be a record breaking day!

Please help Isyana find out the number of record breaking days.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case begins with a line containing the integer N. The second line contains N integers. The i-th integer is Vi.

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 number of record breaking days.

Limits

Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
0 ≤ Vi ≤ 2 × 105.

Test set 1

1 ≤ N ≤ 1000.

Test set 2

1 ≤ N ≤ 2 × 105 for at most 10 test cases.
For the remaining cases, 1 ≤ N ≤ 1000.

Sample


Input
 

Output
 
4
8
1 2 0 7 2 0 2 0
6
4 8 15 16 23 42
9
3 1 4 1 5 9 2 6 5
6
9 9 9 9 9 9
Case #1: 2
Case #2: 1
Case #3: 3
Case #4: 0
#include<bits/stdc++.h>
using namespace std; int main()
{
int t, n;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n;
vector<int> v;
for(int j=0;j<n;j++)
{
int tt;
cin>>tt;
v.push_back(tt);
}
int result = 0;
int max_v = INT_MIN; if(v.size()==1)
result = 1;
else
{
for(int j=0;j<v.size();j++)
{
if(j>=1)
max_v = max(max_v, v[j-1]); if(j<=v.size()-2)
{
if(v[j]>max_v && v[j]>v[j+1])
result++;
}
else
{
if(v[j]>max_v)
result++;
}
}
} printf("Case #%d: %d\n", i, result); }//end of for return 0;
}

第二题:

本题题意复杂些,就是要一堆数字转换成A B C D,数字若是升/降序,则转换成的字母也要是对应的升/降序。问,不满足这种次序关系的有几处。

方法:每出现连续5个降序或者5个升序,则不满足情况+1

Problem

An alien has just landed on Earth, and really likes our music. Lucky for us.

The alien would like to bring home its favorite human songs, but it only has a very strange instrument to do it with: a piano with just 4 keys of different pitches.

The alien converts a song by writing it down as a series of keys on the alien piano. Obviously, this piano will not be able to convert our songs completely, as our songs tend to have many more than 4 pitches.

The alien will settle for converting our songs with the following rules instead:

  • The first note in our song can be converted to any key on the alien piano.
  • For every note after,
    • if its pitch is higher than the previous note, it should be converted into a higher-pitched key than the previous note's conversion;
    • if lower, it should be converted into a lower-pitched key than the previous note's conversion;
    • if exactly identical, it should be converted into the same key as the previous note's conversion.

Note: two notes with the same pitch do not need to be converted into the same key if they are not adjacent.

What the alien wants to know is: how often will it have to break its rules when converting a particular song?

To elaborate, let us describe one of our songs as having notes. The first note we describe as "note 1", the second note "note 2", and the last note "note K."
So note 2 comes immediately after note 1.
Now if note 2 is lower than note 1 in our version of the song, yet converted to an equally-pitched or lower-pitched key (relative to note 2's conversion) in the alien's version of the song, then we consider that a single rule break.
For each test case, return the minimum amount of times the alien must necessarily break one of its rules in converting that song.

Input

The first line of the input gives the number of test cases, TT test cases follow.
Each test case consists of two lines.
The first line consists of a single integer, K.
The second line consists of K space-separated integers, A1A2 ... AK, where Ai refers to the pitch of the i-th note for this test case.

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 minimum number of times that particular test case will require the alien to break its own rules during the conversion process.

Limits

Memory limit: 1GB.
1 ≤ T ≤ 100.
1 ≤ Ai ≤ 106.

Test set 1

Time limit: 20 seconds.
1 ≤ K ≤ 10.

Test set 2

Time limit: 40 seconds.
1 ≤ K ≤ 104.

Sample


Input
 

Output
 
2
5
1 5 100 500 1
8
2 3 4 5 6 7 8 9
Case #1: 0
Case #2: 1
#include<bits/stdc++.h>
using namespace std; int main()
{
int t, a;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>a;
vector<int> v;
for(int j=0;j<a;j++)
{
int tt;
cin>>tt;
v.push_back(tt);
}
int result = 0;
int inc = 0, dec = 0;
for(int j=1;j<v.size();j++)
{
if(v[j]>v[j-1])
{
inc++;
dec = 0;
}
if(v[j]<v[j-1])
{
dec++;
inc = 0;
}
if(inc==4 || dec==4)
{
result++;
inc = 0;
dec = 0;
}
}
printf("Case #%d: %d\n", i, result); } return 0;
}

第三题:

该题是考察树,注意每个人是随机访问一个点,然后向上访问(travel up) 直到树根。然后求图画的节点的期望值。

(对于每个TreeNode需要提前建立parent的索引,暴力法,对于A,B两个人,分别遍历了每个节点,时间复杂度较高,小数据能ac)

Problem

Amadea and Bilva are decorating a rooted tree containing N nodes, labelled from 1 to N. Node 1 is the root of the tree, and all other nodes have a node with a numerically smaller label as their parent.

Amadea and Bilva's decorate the tree as follows:

  • Amadea picks a node of the tree uniformly at random and paints it. Then, she travels up the tree painting every A-th node until she reaches the root.
  • Bilva picks a node of the tree uniformly at random and paints it. Then, she travels up the tree painting every B-th node until she reaches the root.

The beauty of the tree is equal to the number of nodes painted at least once by either Amadea or Bilva. Note that even if they both paint a node, it only counts once.

What is the expected beauty of the tree?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case begins with a line containing the three integers NA and B. The second line contains N-1 integers. The i-th integer is the parent of node i+1.

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 expected beauty of the tree.

y will be considered correct if it is within an absolute or relative error of 10-6 of the correct answer. See the FAQ for an explanation of what that means, and what formats of real numbers we accept.

Limits

Memory limit: 1GB.
1 ≤ T ≤ 100.
1 ≤ A ≤ N.
1 ≤ B ≤ N.

Test set 1

Time limit: 20 seconds.
1 ≤ N ≤ 100.

Test set 2

Time limit: 40 seconds.
For up to 5 cases, 1 ≤ N ≤ 5 × 105.
For all other cases, 1 ≤ N ≤ 100.

Sample


Input
 

Output
 
3
8 2 3
1 1 3 4 4 3 4
10 3 4
1 1 1 1 1 1 1 1 1
4 3 1
1 2 3
Case #1: 2.65625
Case #2: 1.9
Case #3: 2.875
#include<bits/stdc++.h>
using namespace std; struct TreeNode {
int val;
//vector<TreeNode*> child;
TreeNode *parent;
TreeNode(int x) : val(x), parent(NULL){} }; int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
int n,a,b;
cin>>n>>a>>b;
vector<TreeNode*> v(n+1,NULL); v[1] = new TreeNode(1); for(int j=0;j<n-1;j++)
{
int tt;
cin>>tt; v[j+2] = new TreeNode(j+2);
v[j+2] -> parent = v[tt];
} //vector<TreeNode*> vv(v);
set<TreeNode*> s;
int num = 0;
for(int x=1;x<=n;x++)
for(int y=1;y<=n;y++)
{
s.clear();
TreeNode* p = v[x];
TreeNode* q = v[y];
while(p)
{
s.insert(p);
for(int k=1;k<=a;k++)
{
if(!p)
break;
p = p->parent;
}
}// while(q)
{
s.insert(q);
for(int k=1;k<=b;k++)
{
if(!q)
break;
q = q->parent;
}
} num += s.size(); }//end of for x,y
//cout<<"num:"<<num<<endl;
//cout<<"n:"<<n<<endl; double result = num/1.0/(n*n);
//cout<<"result:"<<result<<endl;
printf("Case #%d: %f\n", i, result); } return 0;
}

第四题:

题意:一横排有n个房间,每个房间往左往右走,都可能需要开锁,每次开难度较小的锁,到达尽头则不能继续走。给出si(start)起始房间的号码,求问第ki次进入到了哪个房间。

暴力求解,每次记下了每个房间左右的房间号,记录了左右锁的难度。(问题在于每次初始化,很耗时,所以只有小数据能ac)

Problem

Bangles is preparing to go on a tour of her local museum. The museum is made up of N rooms in a row, numbered from 1 to N from left to right. The rooms are connected by N-1 locked doors, each connecting a pair of adjacent rooms. Each door has a difficulty level indicating how difficult it is for Bangles to open the door. No two doors will have the same difficulty level. The door between the i-th room and (i+1)-th room has difficulty level Di.

Bangles will pick one of the rooms to start in, and visit each of the rooms in the museum one at a time, taking pictures as she goes. She takes a picture in her starting room, then she repeats the following procedure until she has taken a picture in all the rooms: Of the two locked doors available to her, she will open the door with the lower difficulty level and take a picture in the newly unlocked room. If there is only one locked door available to her, then she will unlock that door. Once a door is unlocked, it remains unlocked.

Bangles is not yet sure which room she would like to start in, so she needs you to answer Q queries. For the i-th query, she would like to know: What is the Ki-th room that she will take a picture in if she starts in the Si-th room?

Input

The first line of the input gives the number of test cases, TT test cases follow. The first line of each test case contains the two integers N and Q. The second line contains N-1 integers, describing the locked doors. The i-th integer (starting from 1) is Di. Then, Q lines follow, describing the queries. The i-th of these lines contains the two integers Si and Ki.

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 a list of the answers for the Q queries in order, separated by spaces.

Limits

Time limit: 40 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
1 ≤ Di ≤ 105, for all i.
All Di are distinct.
1 ≤ Si ≤ N, for all i.
1 ≤ Ki ≤ N, for all i.

Test set 1

2 ≤ N ≤ 1000.
1 ≤ Q ≤ 1000.

Test set 2

2 ≤ N ≤ 105 and 1 ≤ Q ≤ 105 for at most 20 test cases.
For the remaining cases, 2 ≤ N ≤ 1000 and 1 ≤ Q ≤ 1000.

Sample


Input
 

Output
 
2
5 4
90 30 40 60
3 4
3 1
1 5
4 3
10 2
6 2 4 5 9 30 7 1 8
6 8
6 8
#include<bits/stdc++.h>
using namespace std; int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
int n, q;
cin>>n>>q;
vector<int> v;
for(int j=0;j<n-1;j++)
{
int tt;
cin>>tt;
v.push_back(tt);
}
vector<int> result; for(int tt=1;tt<=q;tt++)
{
//cout<<"tt:"<<tt<<endl;
vector<int> l_room(n+1,0),r_room(n+1,0),l_value(n+1,0),r_value(n+1,0);
for(int j=1;j<=n;j++)
{
//cout<<"j:"<<j<<endl;
l_room[j] = j-1;
r_room[j] = j+1;
if(j-2>=0)
l_value[j] = v[j-2];
else
l_value[j] = INT_MAX; if(j!=n)
r_value[j] = v[j-1];
else
r_value[j] = INT_MAX;
}
//cout<<"22222"<<endl;
int s,k;
cin>>s>>k; k--; for(int u=1;u<=k;u++)
{ if(l_value[s]<r_value[s])
{
int temp = s;
s = l_room[s];
r_room[s] = r_room[temp];
r_value[s] = r_value[temp];
}
else
{
int temp = s;
s = r_room[s];
l_room[s] = l_room[temp];
l_value[s] = l_value[temp];
}
}
result.push_back(s);
//cout<<"end this"<<endl; } //end of q
printf("Case #%d: ",i);
for(auto u:result)
cout<<u<<" "; cout<<endl; } return 0;
}

kickstart 谷歌 D 2020 年 7 月 12 日 13: 00 - 16: 00的更多相关文章

  1. 7.搭建hyperledger fabric环境及启动——2019年12月12日

    2019年12月12日13:05:16 声明:从网络中学习整理实践而来. 1.介绍fabric Fabric 是一个面向企业应用的区块链框架,基于 Fabric 的开发可以粗略分为几个层面: 1. 参 ...

  2. 北京Uber优步司机奖励政策(3月12日~3月13日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. .NET Conf 2020大会将于2020年11月10日--- 11月12日举行 (UTC)时区

    .NET Conf 2020大会将于2020年11月10日--- 11月12日举行 (UTC)时区 开始时间 2020年11月10日 08:00 (PT) | 16:00 (UTC)| 24:00(北 ...

  4. Swift 3.0首个开发者预览版将在5月12日释出

    Swift团队在博客中宣布Swift 3.0语言首个开发者预览版将于5月12日释出,正式版将在4-6周之后推出.开发者预览阶段并无确定的更新周期和计划,不过Swift团队称努力将其控 制在4-6周内. ...

  5. 系列文章:老项目的#iPhone6与iPhone6Plus适配#(持续更新中,更新日期2014年10月12日 星期日 )

    本文永久地址为http://www.cnblogs.com/ChenYilong/p/4020399.html ,转载请注明出处. ********************************** ...

  6. 2016年12月12日 星期一 --出埃及记 Exodus 21:7

    2016年12月12日 星期一 --出埃及记 Exodus 21:7 "If a man sells his daughter as a servant, she is not to go ...

  7. 2016年11月12日 星期六 --出埃及记 Exodus 20:3

    2016年11月12日 星期六 --出埃及记 Exodus 20:3 "You shall have no other gods before me.除了我以外,你不可有别的 神.

  8. 2016年10月12日 星期三 --出埃及记 Exodus 18:23

    2016年10月12日 星期三 --出埃及记 Exodus 18:23 If you do this and God so commands, you will be able to stand th ...

  9. Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)

    MSDN于2011年5月12日,最新发布简体中文Windows 7 Ultimate 旗舰版 SP1 DVD镜像安装包,分32位和64位两个版本.最新发行代号分别是:677486(32位),67740 ...

随机推荐

  1. powershell渗透-信息收集命令

    powershell渗透-信息收集命令 本文包含从 Internet 的各个角落收集的 PowerShell 命令列表,这些命令在渗透测试或红色团队练习期间可能会有所帮助. 该列表包括各种开发后的单行 ...

  2. Javascript 参数传递

    又一个基本概念出问题,参数传递都是值传递, var a={x:10} function test(obj){obj=1} test(a) console.log(a) 输出什么,如果你说1,那就错了, ...

  3. asyncio多进程+pyppeteer浏览器控制+pyquery解析实现爬虫demo

    import asyncio from pyppeteer import launch from pyquery import PyQuery as pq async def main(): brow ...

  4. Java-Annotation的一种用法(消除代码中冗余的if/else或switch语句)

    Java-Annotation的一种用法(消除代码中冗余的if/else或switch语句) 1.冗余的if/else或switch ​ 有没有朋友写过以下的代码结构,大量的if/esle判断,来选择 ...

  5. phpmyadmin反序列化漏洞(WooYun-2016-199433)

    简介 环境复现:https://github.com/vulhub/vulhub 线上平台:榆林学院内可使用协会内部的网络安全实验平台 phpMyAdmin是一套开源的.基于Web的MySQL数据库管 ...

  6. wireshark分析nmap和metasploit内置的syn扫描

    syn扫描 syn扫描,根据三次握手,向端口发送syn包,如果对方回应SYN/ACK,则证明端口开放 首先是nmap 速度很快,0.67秒完成,看下wireshark的抓取 一次发送了大量的syn包 ...

  7. SpringSecurity了解

    在web开发中,安全第一位!!过滤器.拦截器~ 属于非功能性需求. 做网站:安全应该在什么时候考虑?设计之初!! 漏洞,隐私泄露~ 假设架构一旦确定~ shiro和SpringSecurity的区别: ...

  8. web安全入门--入门条件

    介绍:网络安全由习大大提出,是继海.陆.空.外太空的第五大作战领域,也是一个关系国家安全和主权.社会稳定.民族文化继承和发扬的重要问题.其重要性,正随着全球信息化步伐的加快越来越重要.接下来,我向大家 ...

  9. PVE简单迁移虚拟机

    工作中有2台PVE节点,但是没有做集群,如果有集群可以很方便的进行迁移.本次迁移的目的是: 目前有一台PVE1节点装的虚机资源使用较多,想迁移某台虚机到另一台PVE2. 1 备份 备份在web页面操作 ...

  10. 了解 MySQL的数据行、行溢出机制吗?

    目录 一.行 有哪些格式? 二.紧凑的行格式长啥样? 三.MySQL单行能存多大体量的数据? 四.Compact格式是如何做到紧凑的? 五.什么是行溢出? 六.行 如何溢出? 七.思考一个问题 关注送 ...