概述

题号 标题 已通过代码 通过率 我的状态
A Genshin and KFC 点击查看 1265/1412 通过(直接输出)
B Codeforces 点击查看 1144/2390 通过(直接输出)
C Set Up The Flag 点击查看 1/28 未通过
D LCA On N-ary Tree 点击查看 511/1747 通过(找n叉树的LCA)
E Shortest Path Sum 点击查看 6/104 未通过
F Palindrome 点击查看 307/1723 通过(删2个字符回文串)
G Permutation 点击查看 224/975 通过(维护排列的偏移量贡献)
H Infinite Array 点击查看 1/76 未通过
I String 点击查看 16/242 未通过
J K-clearing 点击查看 826/4533 通过(序列每次减1)
K Matrix 点击查看 26/321 未通过
L Polygon 点击查看 1059/1615 通过(判断n边形)

A Genshin and KFC

链接:https://ac.nowcoder.com/acm/contest/12986/A
来源:牛客网

题目描述
One day, otaku Awei heard that KFC(Kentucky Fried Chicken) has a new activity recently. If you say “Yi Shi Xiang Yu, Jin Xiang Mei Wei!” to the clerk, you will receive a limited badge of Genshin Impact.
As a Genshin Impact player, Awei is eager to get the limited badge, but he is too shy to say that. You should help Awei print the sentence.

输入描述:
No input.
输出描述:
The output contains a line with “Yi Shi Xiang Yu, Jin Xiang Mei Wei!”.(without quote)
示例1
输入
复制
(no input)
输出
复制
Yi Shi Xiang Yu, Jin Xiang Mei Wei!

//直接输出就行
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e5+10;int main(){ios::sync_with_stdio(false);cout<<"Yi Shi Xiang Yu, Jin Xiang Mei Wei!\n";return 0;
}

B Codeforces

链接:https://ac.nowcoder.com/acm/contest/12986/B
来源:牛客网

题目描述
Codeforces is a website that hosts competitive programming contests. It is maintained by a group of competitive programmers from ITMO University. Since 2013, Codeforces claims to surpass Topcoder in terms of active contestants. As of 2018, it has over 600,000 registered users. Codeforces along with other similar websites are used by top sport programmers and by other programmers interested in furthering their career. Codeforces is recommended by many universities. According to Daniel Sleator, professor of Computer Science at Carnegie Mellon University, competitive programming is valuable in computer science education, because competitors learn to adapt classic algorithms to new problems, thereby improving their understanding of algorithmic concepts.
In codeforces contestants are divided into ranks based on their ratings:
≥3000
Legendary Grandmaster
2400 - 2999
Grandmaster
2100 - 2399
Master
1900 - 2099
Candidate Master
1600 - 1899
Expert
1400 - 1599
Specialist
1200 - 1399
Pupil
0 - 1199
Newbie
After a contest, the rating of the contestant will change. In this problem, you are given a contestant’s rating before and after the contest. You need to answer whether the title has changed. If it has changed, please output the original and changed title.
输入描述:
The first line contains an integer t(1\leq t\leq100){}t(1≤t≤100)

— the number of test cases, each test case contains two integers a
{}a

and b(0\leq a,b \leq 4000){}b(0≤a,b≤4000)

representing contestant’s rating before and after the contest.
输出描述:
If the title has changed, please output in the form of “Original
{}Original

to Changed_{}Changed

”, otherwise output “No”.
示例1
输入
复制
3
1145 1419
1981 0
3000 4000
输出
复制
Newbie to Specialist
Candidate Master to Newbie
No

//直接输出就行
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e5+10;string change(int x){if(x>=3000)return "Legendary Grandmaster";if(x>=2400)return "Grandmaster";if(x>=2100)return "Master";if(x>=1900)return "Candidate Master";if(x>=1600)return "Expert";if(x>=1400)return "Specialist";if(x>=1200)return "Pupil";return "Newbie";
}
int main(){ios::sync_with_stdio(false);int T;  cin>>T;while(T--){int a, b;   cin>>a>>b;string aa = change(a), bb = change(b);if(aa==bb)cout<<"No\n";else cout<<aa<<" to "<<bb<<"\n";}return 0;
}

D LCA On N-ary Tree

链接:https://ac.nowcoder.com/acm/contest/12986/D
来源:牛客网

题目描述
The N-ary tree is a tree that each node has exactly n_{}n

child nodes.
You are given an N-ary tree with infinite nodes, each node is numbered from 1_{}1

to infinity according to the level order(from left to right, level by level).

                                        The first 13 nodes on the 3-ary tree.

Given the number x_{}x

and y_{}y

of the two nodes, you have to calculate the lowest common ancestors(LCA) of these two nodes.
Definition of the lowest common ancestors(LCA): The LCA of two nodes on the tree refers to the node is the ancestor of these two nodes with the shortest distance to these two nodes, it should be noted that the node itself is also considered its own ancestor. For example, on the 3-ary tree the LCA of node 6_{}6

and node 3_{}3

is node 1_{}1

.
输入描述:
The first line contains an integer t(1\leq t\leq10^5){}t(1≤t≤10
5
)

— the number of test cases.
Each test case contains three integers n,x,y(1\leq n,x,y\leq 10^9)
{}n,x,y(1≤n,x,y≤10
9
)

representing the tree is an n-ary tree and number of two nodes.
输出描述:
For each test case output a positive integer to represent the LCA of the given two nodes.
示例1
输入
复制
4
1 2 3
2 4 6
3 6 3
10000 10000 10000
输出
复制
2
1
1
10000

//题意:1e5组数据,每组n,u,v,每次求n叉树中u和v的LCA(最近公共祖先)。
//思路:考虑n叉树的性质,节点是层序编号的,可以发现x可以通过(x-1)/n跳到上一层的节点,所以先把y向上跳到和x同一层,然后x和y一起往上跳直到一起就行。判断同一层的条件为小于满n叉树第h层的最后一个节点的编号,可以直接枚举获得不会超时,卡超时的点是输入的cin和scanf优化。
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e6+10;int main(){int T;  scanf("%d",&T);while(T--){LL n, x, y; scanf("%lld%lld%lld",&n,&x,&y);if(n==1 || x==y){printf("%lld\n", min(x,y));continue;}if(x>y)swap(x,y);LL num = 0, pp = 1;while(num<x){ num+=pp; pp*=n;}while(y>num){if(y%n==0||(y-1)%n==0)y=y/n;else y = y/n+1;}while(x!=y){if(x%n==0||(x-1)%n==0)x=x/n;else x = x/n+1;if(y%n==0||(y-1)%n==0)y=y/n;else y = y/n+1;}printf("%lld\n",x);}return 0;
}

F Palindrome

链接:https://ac.nowcoder.com/acm/contest/12986/F
来源:牛客网

题目描述
You are given a string s_{}s

of n_{}n

lowercase letters.
You have to delete exactly two letters from s_{}s

, determine whether the string can become a palindrome after the change.
Definition of palindrome: If a string s_{}s

of n_{}n

lowercase letters is a palindrome, then for each s_i(1\leq i\leq n)s
i

(1≤i≤n) ,
s_i=s_{n-i+1}s
i

=s
n−i+1

.
For example, “ababa” and “abba” are palindromes, but “abab” not.
输入描述:
The first line contains an integer t(1\leq t\leq10^3){}t(1≤t≤10
3
)

— the number of test cases.
For each test case, the first line contains an integer n(3\leq n\leq 2!\cdot!10^3)
{}n(3≤n≤2⋅10
3
)

representing the length of s_{}s

, the second line contains a string of length n_{}n

.
It is guaranteed that the sum of n_{}n

for all test cases does not exceed 10^4_{}10
4

.
输出描述:
If it is possible to change the string into a palindrome after deleting two letters from s_{}s

, please output “Yes”, otherwise output “No”.
示例1
输入
复制
3
4
abca
6
ababab
6
abcabc
输出
复制
Yes
Yes
No

//题意:给出一个长为n的字符串,必须删除任意2个字符,求能否形成一个回文串。
//思路:考虑到如果本来是回文串,那么删两个肯定还是回文,如果本来不是,那就相当于两次试错机会。因为只有2次,所以直接暴力模拟,a[l]!=a[r]的时候就跳过,左右分类一共四类,都不行就是不行了,只要有一个可以,更新到答案就行。
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e6+10;string a;
int del2(int l, int r){while(l<r){if(a[l]==a[r]){l++; r--;}else{return 0;}}return 1;
}
int del1(int l, int r){while(l<r){if(a[l]==a[r]){l++; r--;}else{if(del2(l+1,r))return 1;if(del2(l,r-1))return 1;return 0;}}return 1;
}int main(){ios::sync_with_stdio(false);int T;  cin>>T;while(T--){int n;  cin>>n;cin>>a;int l = 0, r = n-1, ok = 0;while(l<r){if(a[l]==a[r]){l++; r--;}else{if(del1(l+1,r)){ok = 1; break;}if(del1(l,r-1)){ok = 1; break;}ok = 0; break;}}if(l>=r)ok = 1;if(ok==1)cout<<"Yes\n";else cout<<"No\n";}return 0;
}

G Permutation

链接:https://ac.nowcoder.com/acm/contest/12986/G
来源:牛客网

题目描述
You are given two permutations a_{}a

and b_{}b

of length n_{}n

.
A permutation is a sequence of length n_{}n

integers from 1_{}1

to n_{}n

, in which all the numbers occur exactly once. For example, [1], [1,3,2], [3,1,5,2,4]{}[1],[1,3,2],[3,1,5,2,4]

are permutations, and [2], [1,1]
{}[2],[1,1]

are not.
There are two types of operations as follow:
Remove the first integer in a_{}a

. Then append any integer at the end of a_{}a

.
Choose an a_i(1\leq i\leq n)a
i

(1≤i≤n) and modify it to any integer.
You have to find the minimum number of operations to make a_{}a

and b_{}b

the same.
Be attention, you do not have to keep a_{}a

in a permutation during the process.
输入描述:
The first line contains an integer n(1\leq n\leq 10^6){}n(1≤n≤10
6
)

— the length of a
{}a

and b_{}b

.
The second line contains n_{}n

integers a_1,a_2,…,a_n(1\leq a_i\leq n)a
1

,a
2

,…,a
n

(1≤a
i

≤n) .
The third line contains n_{}n

integers b_1,b_2,…,b_n(1\leq b_i\leq n)b
1

,b
2

,…,b
n

(1≤b
i

≤n) .
It is guaranteed that a_{}a

and b_{}b

are both permutations.
输出描述:
Output the minimum number of operations to make a_{}a

and b_{}b

the same.
示例1
输入
复制
5
5 2 3 4 1
5 3 2 1 4
输出
复制
3
说明
For the first example, there is a possible way:

  1. Remove the first integer in a_{}a

    and append 4, now a_{}a

    becomes [2,3,4,1,4]_{}[2,3,4,1,4]

    .
  2. modify a_1a
    1

    to 5_{}5

    , now a_{}a

    becomes [5,3,4,1,4]_{}[5,3,4,1,4]

    .
  3. modify a_3a
    3

    to 2_{}2

    , now a_{}a

    becomes [5,3,2,1,4]{}[5,3,2,1,4]

    .
    So it only takes 3
    {}3

    operations to convert a_{}a

    into b_{}b

    .
//题意:给出两个长为n的全排列,求排列a最少通过多少次操作可以成为排列2。有两种操作,一种是a左移一位并且右边补任意数字,另一种是把任意一位换成任意一个数字。
/*思路:
+ 考虑到左移是为了对齐,右边可以补上任意的,所以移动一次肯定>=1,而交换只有1,并且一边交换一边移最后的结果一定不会更优(移了就没了),所以先直接移动。
+ 因为移动几位会超时,并且考虑到全排列没有重复数字的特殊性,所以考虑每个数字的贡献,可以维护一个数组记录数字i在a[i]中的位置,这样对于b[i]就可以O(1)知道他们的位置偏移量和差值,再维护一个数组统计相同偏移量差值的值的数量,取最大的就是要移动的位数,最后可以O(1)算出答案。
+ 因为a只能往左边移,所以对于a[j]种在b[i],j<i,即a中在b还要前面的位置,肯定无法移到,直接continue就行。
*/
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e6+10;
int a[maxn], b[maxn], f[maxn];
//map<int,int>ff;
int ff[5*maxn];
int main(){int n;  scanf("%d",&n);for(int i = 1; i <= n; i++){scanf("%d", &a[i]);  f[a[i]] = i;}int cnt = 0;int mx = 0, t;for(int i = 1; i <= n; i++){scanf("%d", &b[i]);if(a[i]!=b[i])cnt++;int kk = f[b[i]]-i;//+maxn;if(kk<0)continue;ff[kk]++;if(ff[kk]>mx){mx = ff[kk];t = kk;}}//cout<<mx<<" "<<t<<"\n";int ans = min(t+(n-t-mx),cnt);//int ans = t+(n-t-mx);cout<<ans<<"\n";return 0;
}

J K-clearing

链接:https://ac.nowcoder.com/acm/contest/12986/J
来源:牛客网

题目描述
You are given an array a_{}a

of n_{}n

integers. You have to clearing all elements equal to k_{}k

in this array.
When there is at least one element equal to k_{}k

in the array, then you should make all the positive elements in the array minus one. In other words, a_i=a_i-1(1\leq i\leq n;a_i > 0)a
i

=a
i

−1(1≤i≤n;a
i

0) .
When the array does not have any element equal to k_{}k

, please output the array.
输入描述:
The first line contains two integers n(1\leq n\leq 10^6){}n(1≤n≤10
6
)

, k(1\leq k\leq 10^9)
{}k(1≤k≤10
9
)

— the length of a_{}a

and the number we need to clear.
The second line contains n_{}n

integers a_1,a_2,…,a_n(1\leq a_i\leq 10^9)a
1

,a
2

,…,a
n

(1≤a
i

≤10
9
) .
输出描述:
Output the array when the array does not have any element equal to k_{}k

.
Please do not output extra blank spaces at the end of the output.
示例1
输入
复制
5 1
5 2 3 4 1
输出
复制
0 0 0 0 0
示例2
输入
复制
6 1
1 1 4 5 1 4
输出
复制
0 0 3 4 0 3

//题意:给出一个长为n的数字和一个数字k,每次如果数组中有等于k的数字就数组每个数字减去1,直到没有数字等于k为止。
//思路:最开始没有就肯定没了, 如果有,那全部减一还会有吗,只有在原数组中有k+1的情况下才会有,所以就很容易想到数组中有k,k+1,k+2,k+3,,,一直连到哪里,就会一直减去,知道把最大的k+x减小到k-1为止,所以答案就是找到k+x,然后输出每个数减去((k+x)-(k-1))。对于k+x,可以开个set维护数组中的数,从k开始一直加到没有没有连续的位置。
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e6+10;
LL a[maxn];
set<LL>se;
int main(){ios::sync_with_stdio(false);LL n, k;  cin>>n>>k;for(int i = 1; i <= n; i++){ cin>>a[i]; se.insert(a[i]);}LL kk = k;while(se.count(kk)){kk++;}kk--;//cout<<kk<<"\n";LL cha = kk-(k-1);if(!se.count(k)){for(int i = 1; i <= n; i++)cout<<a[i]<<" ";}else{for(int i = 1; i <= n; i++){if(a[i]<=cha)cout<<"0 ";else cout<<a[i]-cha<<" ";}}return 0;
}

L Polygon

链接:https://ac.nowcoder.com/acm/contest/12986/L
来源:牛客网

题目描述
Given the length of n_{}n

edges, determine whether these edges can be used to form an n_{}n

-polygon which has positive area.

Examples of 3-polygon, 4-polygon and 6-polygon.

输入描述:
The first line contains a single integer n (3 \leq n \leq 100){}n(3≤n≤100)

, the number of edges.
The next line contains n
{}n

integers a_{1},a_{2},…,a_{n} (1 \leq a_{i} \leq 100)a
1

,a
2

,…,a
n

(1≤a
i

≤100) , the length of i_{th}i
th

edges.
输出描述:
If the n_{}n

edges can form a n_{}n

-polygon, output “Yes”, otherwise output “No”.(without quote)
示例1
输入
复制
3
1 2 3
输出
复制
No
示例2
输入
复制
5
5 5 5 5 5
输出
复制
Yes

//题意:给出n条边,判断能否构成n边形。
//思路:数学结论,任意n-1条边之和大于第n条边。
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int main(){ios::sync_with_stdio(false);int n;  cin>>n;int sum = 0;for(int i = 1; i <= n; i++){ cin>>a[i]; sum += a[i];}int ok = 1;for(int i = 1; i <= n; i++){if(sum-a[i]<=a[i]){ok = 0; break;}}if(ok==1)cout<<"Yes\n";else cout<<"No\n";return 0;
}

第十八届浙大城市学院程序设计竞赛(同步赛)签到题ABDFGJL相关推荐

  1. 2021年广东工业大学第11届腾讯杯新生程序设计竞赛(同步赛)错题笔记

    目录: 题目链接 A 比比谁更大 B 过生日 D 机器人 G 拼牛牛 I 史莱姆 J 水题 K 烧烤丝瓜 L 歪脖子树下的灯 题目链接 A 比比谁更大 题目描述 在一个夜黑风高的晚上,牛哥哥吃完心爱的 ...

  2. 【十九届浙大城市学院程序设计竞赛 - 周训】

    Who is The 19th ZUCCPC Champion Jiubei and Overwatch Ah, It's Yesterday Once More Sum of Numerators ...

  3. 第十九届浙大城市学院程序设计竞赛

    I.Array Division 数组分组,要求每组的和大于等于0,求最多可以分成几组. #include<bits/stdc++.h>using namespace std;#defin ...

  4. 哈尔滨理工大学21级新生程序设计竞赛(同步赛)错题笔记

    目录: 新生赛题目链接 C kiki和bob玩取石子 E 很二的拆分 F 构造字符串 G 信号之旅 H 小球滚动 I kiki看球赛 J 跳一跳 K Jay的小迷弟 L 翻转卡片 新生赛题目链接 C ...

  5. 牛客练习-哈尔滨理工大学21级新生程序设计竞赛(同步赛)

    比赛链接:哈尔滨理工大学21级新生程序设计竞赛(同步赛) 文章目录 前言 正文 A.考试周破防 B.咖啡店 C.kiki和bob玩取石子 D.猴王kiki分桃 E.很二的拆分 F.构造字符串 G.信号 ...

  6. “科林明伦杯”哈尔滨理工大学第十届程序设计竞赛(同步赛) 题解

    "科林明伦杯"哈尔滨理工大学第十届程序设计竞赛(同步赛) 题解 萌新又来写题解啦 原题链接 B 减成一 题意:存在n个数,每次操作可以任选一个区间使得区间内的所有数字减一.问最少多 ...

  7. 哈尔滨理工大学软件与微电子学院程序设计竞赛(新生赛)

    关于哈尔滨理工大学软件与微电子学院程序设计竞赛(新生赛) 下午五点四十开始的比赛,五点二十我才刚刚抽完血,实在是有点难顶,再加上还没有吃饭,刚开始做题的时候还真是有点发懵,胳膊也很难受. 这应该是我第 ...

  8. 【牛客 - 301哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级 )】小乐乐和25(模拟,技巧)

    题干: 小乐乐特别喜欢25这个数字,他想把所有的数字都变成25的倍数. 现在小乐乐得到一个数字,想问问你最少用几次操作才可以把这个数字改造成25的倍数. 对于一次操作我们可以把相邻的两位做交换,比如1 ...

  9. 【牛客 - 301哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级)】小乐乐搭积木(状压dp)

    题干: 小乐乐想要给自己搭建一个积木城堡. 积木城堡我们假设为n*m的平面矩形. 小乐乐现在手里有1*2,2*1两种地砖. 小乐乐想知道自己有多少种组合方案. 输入描述: 第一行输入整数n,m.(1& ...

最新文章

  1. 软件开发文档模板 (学习)
  2. ajax传递json数组php,怎么通过ajax传送json数组到php,并通过php将数据插入数据库
  3. 计算机加一块硬盘,老电脑卡顿不一定没救了 加一块SSD就能焕发新生
  4. NHibernate 3.x新功能实践(二) QueryOver(下)
  5. 6.Python深入_内存管理
  6. kNN(k-nearest-neighbor)算法的Python实现
  7. python离线安装tensorflow_TensorFlow 在Linux系统下离线安装
  8. 这回真的要和雅虎再见了 雅虎将转型为投资机构
  9. 微信公众号API接口调用
  10. Qt:局域网文件同步工具
  11. ios kb转m_字节、kb、M怎么换算
  12. Linux Thermal机制源码分析之Thermal zone
  13. php rsa 跨平台问题,为啥 rsa 这种算法扩展 php/python 不自带。而且跨平台也不是处理的很好...
  14. Win32API大全
  15. 任正非圣诞发表文章:我在生活所迫时创立华为
  16. 如何解决下载链接在微信中无法打开的问题的?
  17. 可靠性设计原则1000条
  18. 一文搞懂各种架构(业务架构、应用架构、数据架构...
  19. Python之程序交互
  20. python networkx 边权重_Python / NetworkX:通过边缘发生频率向边缘添加权重

热门文章

  1. (单层)感知机学习规则
  2. 除法运算、商、余数与取模
  3. Git 基础(八)—— Github 的使用(账号管理)
  4. C++ 设计模式 —— 控制器设计模式(实现功能模块间通信)
  5. HBase 的(伪)分布式安装
  6. python3.6安装步骤-python3.6、opencv安装环境搭建过程(图文教程)
  7. python函数定义及调用-Python函数的基本定义和调用以及内置函数
  8. python入门经典100题-Python3基础训练经典100题(带答案)下载
  9. 零基础学python用哪本书好-零基础想要学习Python编程 ,不知道看哪本书?
  10. HTK语音识别示例(Ubuntu)