之前python课程设计的作业
没有什么新意,就是用python写了个合成大罗马
不过自己对库的使用理解更深了
1 | from pygame.draw import rect |
更改了一下,能够像是正常的贪吃蛇了。。。
1 | import pygame |
链接:https://ac.nowcoder.com/acm/contest/11168/C
来源:牛客网
题目描述
给定一棵 n 个点的带点权的有根树,根节点为 1 。
要选出两个节点,满足任意一个不是另一个的祖先节点,最大化以两个节点为根的子树的点权和 。
如果选不出两棵合法的子树,则输出“Error”。
输入描述:
第一行一个正整数 n 。
第二行 n 个整数,分别表示 n 个点的点权 。
接下来 n - 1 行,每行两个正整数 u,v 表示 u 和 v 之间有一条连边 。
输出描述:
一个整数,表示最大的点权和
样例
1 | 5 |
1 | 13 |
这题的题目的意思是要你找出两个父节点不一样的两个节点,使得他们的子树权和最大
这里使用dfs递归从底往上更新mx数组,mx数组的意思是mx以下的后代节点的点权和
而sum数组的意思是以u为根节点的子树权和
使用邻接表储存树即可
我们找出最大的和次大的即可
1 | #include<iostream> |
链接:https://vjudge.z180.cn/problem/UVA-11054
来源:vjudge
As you may know from the comic “Asterix and the Chieftain’s Shield”, Gergovia consists of one street,
and every inhabitant of the city is a wine salesman. You wonder how this economy works? Simple
enough: everyone buys wine from other inhabitants of the city. Every day each inhabitant decides how
much wine he wants to buy or sell. Interestingly, demand and supply is always the same, so that each
inhabitant gets what he wants.
There is one problem, however: Transporting wine from one house to another results in work. Since
all wines are equally good, the inhabitants of Gergovia don’t care which persons they are doing trade
with, they are only interested in selling or buying a specific amount of wine. They are clever enough
to figure out a way of trading so that the overall amount of work needed for transports is minimized.
In this problem you are asked to reconstruct the trading during one day in Gergovia. For simplicity
we will assume that the houses are built along a straight line with equal distance between adjacent
houses. Transporting one bottle of wine from one house to an adjacent house results in one unit of
work.
Input
The input consists of several test cases. Each test case starts with the number of inhabitants n
(2 ≤ n ≤ 100000). The following line contains n integers ai (−1000 ≤ ai ≤ 1000). If ai ≥ 0, it
means that the inhabitant living in the i-th house wants to buy ai bottles of wine, otherwise if ai < 0,
he wants to sell −ai bottles of wine. You may assume that the numbers ai sum up to 0.
The last test case is followed by a line containing ‘0’.
Output
For each test case print the minimum amount of work units needed so that every inhabitant has his
demand fulfilled. You may assume that this number fits into a signed 64-bit integer (in C/C++ you
can use the data type “long long”, in JAVA the data type “long”).
1 | 5 |
1 | 9 |
把a+b+c+d=0的问题转化成a+b=-(c+d)问题
写一个map然后加起来即可
1 | #include<iostream> |
链接:https://vjudge.z180.cn/problem/UVA-210
来源:uva
题目描述
Programs executed concurrently on a uniprocessor system appear to be executed at the same time, but
in reality the single CPU alternates between the programs, executing some number of instructions from
each program before switching to the next. You are to simulate the concurrent execution of up to ten
programs on such a system and determine the output that they will produce.
The program that is currently being executed is said to be running, while all programs awaiting
execution are said to be ready. A program consists of a sequence of no more than 25 statements, one
per line, followed by an end statement. The statements available are listed below.
Statement Type Syntax
Assignment variable = constant
Output print variable
Begin Mutual Exclusion lock
End Mutual Exclusion unlock
Stop Execution end
A variable is any single lowercase alphabetic character and a constant is an unsigned decimal number less than 100. There are only 26 variables in
the computer system, and they are shared among
the programs. Thus assignments to a variable
in one program affect the value that might be
printed by a different program. All variables are
initially set to zero.
Each statement requires an integral number of time units to execute. The running program is
permitted to continue executing instructions for a period of time called its quantum. When a program’s
time quantum expires, another ready program will be selected to run. Any instruction currently being
executed when the time quantum expires will be allowed to complete.
Programs are queued first-in-first-out for execution in a ready queue. The initial order of the ready
queue corresponds to the original order of the programs in the input file. This order can change,
however, as a result of the execution of lock and unlock statements.
The lock and unlock statements are used whenever a program wishes to claim mutually exclusive
access to the variables it is manipulating. These statements always occur in pairs, bracketing one or
more other statements. A lock will always precede an unlock, and these statements will never be
nested. Once a program successfully executes a lock statement, no other program may successfully
execute a lock statement until the locking program runs and executes the corresponding unlock
statement. Should a running program attempt to execute a lock while one is already in effect, this
program will be placed at the end of the blocked queue. Programs blocked in this fashion lose any of their
current time quantum remaining. When an unlock is executed, any program at the head of the blocked
queue is moved to the head of the ready queue. The first statement this program will execute when
it runs will be the lock statement that previously failed. Note that it is up to the programs involved
to enforce the mutual exclusion protocol through correct usage of lock and unlock statements. (A
renegade program with no lock/unlock pair could alter any variables it wished, despite the proper use
of lock/unlock by the other programs.)
输入描述:
The input begins with a single positive integer on a line by itself indicating the number of the cases
following, each of them as described below. This line is followed by a blank line, and there is also a
blank line between two consecutive inputs.
The first line of the input file consists of seven integers separated by spaces. These integers specify
(in order): the number of programs which follow, the unit execution times for each of the five statements
(in the order given above), and the number of time units comprising the time quantum. The remainder
of the input consists of the programs, which are correctly formed from statements according to the
rules described above.
All program statements begin in the first column of a line. Blanks appearing in a statement should
be ignored. Associated with each program is an identification number based upon its location in the
input data (the first program has ID = 1, the second has ID = 2, etc.).
输出描述:
For each test case, the output must follow the description below. The outputs of two consecutive cases
will be separated by a blank line.
Your output will contain of the output generated by the print statements as they occur during the
simulation. When a print statement is executed, your program should display the program ID, a colon,
a space, and the value of the selected variable. Output from separate print statements should appear
on separate lines.
样例
1 | 3 3 |
1 | 1: 3 |
有很多坑点,这题的主要思想是模拟多线程运行程序,所以每一行指令要用数组来映射。。。
这题目理解难度(一定是我太菜了)还挺大的,理解了题目的要求还是有坑点,比如说lock如果没声明成全局变量也会wa
而且其实题目他是有多个样例的,但是vj和紫书上都没说,也挺坑的。。。不过写出代码后难度也就那样吧
加油!!
1 | #include<iostream> |
链接:https://vjudge.z180.cn/problem/UVA-1592
来源:uva
题目描述
Peter studies the theory of relational databases. Table in the relational database consists of values that
are arranged in rows and columns.
There are different normal forms that database may adhere to. Normal forms are designed to
minimize the redundancy of data in the database. For example, a database table for a library might
have a row for each book and columns for book name, book author, and author’s email.
If the same author wrote several books, then this representation is clearly redundant. To formally
define this kind of redundancy Peter has introduced his own normal form. A table is in Peter’s Normal
Form (PNF) if and only if there is no pair of rows and a pair of columns such that the values in the
corresponding columns are the same for both rows.
How to compete in ACM ICPC Peter peter@neerc.ifmo.ru
How to win ACM ICPC Michael michael@neerc.ifmo.ru
Notes from ACM ICPC champion Michael michael@neerc.ifmo.ru
The above table is clearly not in PNF, since values for 2rd and 3rd columns repeat in 2nd and
3rd rows. However, if we introduce unique author identifier and split this table into two tables — one
containing book name and author id, and the other containing book id, author name, and author email,
then both resulting tables will be in PNF.
How to compete in ACM ICPC 1
How to win ACM ICPC 2
Notes from ACM ICPC champion 2
1 Peter peter@neerc.ifmo.ru
2 Michael michael@neerc.ifmo.ru
Given a table your task is to figure out whether it is in PNF or not.
输入描述:
Input contains several datasets. The first line of each dataset contains two integer numbers n and m
(1 ≤ n ≤ 10000, 1 ≤ m ≤ 10), the number of rows and columns in the table. The following n lines
contain table rows. Each row has m column values separated by commas. Column values consist of
ASCII characters from space (ASCII code 32) to tilde (ASCII code 126) with the exception of comma
(ASCII code 44). Values are not empty and have no leading and trailing spaces. Each row has at most
80 characters (including separating commas).
输出描述:
For each dataset, if the table is in PNF write to the output file a single word “YES” (without quotes).
If the table is not in PNF, then write three lines. On the first line write a single word “NO” (without
quotes). On the second line write two integer row numbers r1 and r2 (1 ≤ r1, r2 ≤ n, r1 ̸= r2), on
the third line write two integer column numbers c1 and c2 (1 ≤ c1, c2 ≤ m, c1 ̸= c2), so that values in
columns c1 and c2 are the same in rows r1 and r2
样例
1 | 3 3 |
1 | NO |
很好的题,学会了getline()以某字符为分割符的读取方式
使用方法需要使用到sstream,stringstream流ss,放置的字符串对象st,
getline(ss,st,分割符);
还有二级索引,使得比较的时间大幅度缩减,判断是否已经存在该键值,如果存在该键值则返回对应的数字键值
map<对象,int>index;
int getid(对象){
if(index.find(对象)==index.end())index[对象]=index.size();
return index[对象];
}
说起来都忘了find函数的用法了- -直接用的map对象的find函数,返回的it对象好像和普通的find函数差不多。。。
随意枚举列,成对的枚举,然后判断对应的行与列是否能够有匹配的键值,如果有相同的则输出NO
否则输出YES
1 | #include<iostream> |
链接:https://vjudge.z180.cn/problem/UVA-400
来源:uva
题目描述
The computer company you work for is introducing a brand new computer line and is developing a
new Unix-like operating system to be introduced along with the new computer. Your assignment is to
write the formatter for the ls function.
Your program will eventually read input from a pipe (although for now your program will read
from the input file). Input to your program will consist of a list of (F) filenames that you will sort
(ascending based on the ASCII character values) and format into (C) columns based on the length (L)
of the longest filename. Filenames will be between 1 and 60 (inclusive) characters in length and will be
formatted into left-justified columns. The rightmost column will be the width of the longest filename
and all other columns will be the width of the longest filename plus 2. There will be as many columns
as will fit in 60 characters. Your program should use as few rows (R) as possible with rows being filled
to capacity from left to right.
输入描述:
The input file will contain an indefinite number of lists of filenames. Each list will begin with a line
containing a single integer (1 ≤ N ≤ 100). There will then be N lines each containing one left-justified
filename and the entire line’s contents (between 1 and 60 characters) are considered to be part of the
filename. Allowable characters are alphanumeric (a to z, A to Z, and 0 to 9) and from the following set
{._-} (not including the curly braces). There will be no illegal characters in any of the filenames and
no line will be completely empty.
Immediately following the last filename will be the N for the next set or the end of file. You should
read and format all sets in the input file.
输出描述:
For each set of filenames you should print a line of exactly 60 dashes (-) followed by the formatted
columns of filenames. The sorted filenames 1 to R will be listed down column 1; filenames R + 1 to 2R
listed down column 2; etc.
样例
1 | 10 |
1 | ------------------------------------------------------------ |
主要是输出格式问题,🦅语不好的硬伤就是不太好懂题目
输入了n个整数后跟着n个字符串,直接sort一下,字典序
关键是行与列的公式
M为最长的字符串长度
cols=(maxcols-M)/(M+2)+1,rows=(n-1)/cols+1
1 | #include<iostream> |
链接:https://ac.nowcoder.com/acm/problem/114066
来源:牛客网
题目描述
Some message encoding schemes require that an encoded message be sent in two parts. The first part,
called the header, contains the characters of the message. The second part contains a pattern that
represents the message. You must write a program that can decode messages under such a scheme.
The heart of the encoding scheme for your program is a sequence of “key” strings of 0’s and 1’s as
follows:
0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, . . . , 1011, 1110, 00000, . . .
The first key in the sequence is of length 1, the next 3 are of length 2, the next 7 of length 3, the
next 15 of length 4, etc. If two adjacent keys have the same length, the second can be obtained from
the first by adding 1 (base 2). Notice that there are no keys in the sequence that consist only of 1’s.
The keys are mapped to the characters in the header in order. That is, the first key (0) is mapped
to the first character in the header, the second key (00) to the second character in the header, the kth
key is mapped to the kth character in the header. For example, suppose the header is:
AB#TANCnrtXc
Then 0 is mapped to A, 00 to B, 01 to #, 10 to T, 000 to A, …, 110 to X, and 0000 to c.
The encoded message contains only 0’s and 1’s and possibly carriage returns, which are to be ignored.
The message is divided into segments. The first 3 digits of a segment give the binary representation
of the length of the keys in the segment. For example, if the first 3 digits are 010, then the remainder
of the segment consists of keys of length 2 (00, 01, or 10). The end of the segment is a string of 1’s
which is the same length as the length of the keys in the segment. So a segment of keys of length 2 is
terminated by 11. The entire encoded message is terminated by 000 (which would signify a segment
in which the keys have length 0). The message is decoded by translating the keys in the segments
one-at-a-time into the header characters to which they have been mapped.
输入描述:
The input file contains several data sets. Each data set consists of a header, which is on a single line
by itself, and a message, which may extend over several lines. The length of the header is limited
only by the fact that key strings have a maximum length of 7 (111 in binary). If there are multiple
copies of a character in a header, then several keys will map to that character. The encoded message
contains only 0’s and 1’s, and it is a legitimate encoding according to the described scheme. That is,
the message segments begin with the 3-digit length sequence and end with the appropriate sequence of
1’s. The keys in any given segment are all of the same length, and they all correspond to characters in
the header. The message is terminated by 000.
Carriage returns may appear anywhere within the message part. They are not to be considered as
part of the message.
输出描述:
For each data set, your program must write its decoded message on a separate line. There should not
be blank lines between messages.
样例
1 | TNM AEIOU |
1 | TAN ME |
其实只要读懂readcode即可
readcode的核心思想其实就是
0
00 01 10
000 001 010 011 100 101 110
看到什么规律了吗?对的其实就是二进制而已
只不过前面多了些零,我们用二维数组即可
1 | #include<iostream> |
缺失模块。
1、请确保node版本大于6.2
2、在博客根目录(注意不是yilia根目录)执行以下命令:
npm i hexo-generator-json-content --save
3、在根目录_config.yml里添加配置:
jsonContent: meta: false pages: false posts: title: true date: true path: true text: false raw: false content: false slug: false updated: false comments: false link: false permalink: false excerpt: false categories: false tags: true