Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulting chain will be treated as another segment of rope and can be folded again. After each chaining, the lengths of the original two segments will be halved.
Your job is to make the longest possible rope out of N given segments.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (2 <= N <= 104). Then N positive integer lengths of the segments are given in the next line, separated by spaces. All the integers are no more than 104.
Output Specification:
For each case, print in a line the length of the longest possible rope that can be made by the given segments. The result must be rounded to the nearest integer that is no greater than the maximum length.
intmain(){ int n = 0; scanf("%d", &n); priority_queue<int, vector<int>, greater<int> > q; for (int i = 0; i < n; i++) { int temp = 0; scanf("%d", &temp); q.push(temp); }
while (q.size() > 1) { int a = q.top(); q.pop(); int b = q.top(); q.pop();
John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo – that is, he would select winners from every N followers who forwarded his post, and give away gifts. Now you are supposed to help him generate the list of winners.
Input Specification:
Each input file contains one test case. For each case, the first line gives three positive integers M (<= 1000), N and S, being the total number of forwards, the skip number of winners, and the index of the first winner (the indices start from 1). Then M lines follow, each gives the nickname (a nonempty string of no more than 20 characters, with no white space or return) of a follower who has forwarded John’s post. Note: it is possible that someone would forward more than once, but no one can win more than once. Hence if the current candidate of a winner has won before, we must skip him/her and consider the next one.
Output Specification:
For each case, print the list of winners in the same order as in the input, each nickname occupies a line. If there is no winner yet, print “Keep going…” instead.
intmain(){ int m = 0, n = 0, s = 0; cin >> m >> n >> s; vector<string> forward(m + 1); for (int i = 1; i <= m; i++) { string nickname; cin >> nickname; forward[i] = nickname; }
if (s > m) { cout << "Keep going..." << endl; } else { map<string, bool> winner; cout << forward[s] << endl; winner[forward[s]] = true; int i = s; while (i < m) { int cnt = 0; while (i < m && cnt < n) { i++; if (!winner[forward[i]]) { cnt++; } } if (n == cnt) { cout << forward[i] << endl; winner[forward[i]] = true; } } } return0; }
For a student taking the online course “Data Structures” on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final grade no less than 60 out of 100. The final grade is calculated by G = (Gmid-termx 40% + Gfinalx 60%) if Gmid-term > Gfinal, or Gfinal will be taken as the final grade G. Here Gmid-term and Gfinal are the student’s scores of the mid-term and the final exams, respectively. The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.
Input Specification:
Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on the final exam list. All the numbers are no more than 10,000. Then three blocks follow. The first block contains P online programming scores Gp’s; the second one contains M mid-term scores Gmid-term’s; and the last one contains N final exam scores Gfinal’s. Each score occupies a line with the format: StudentID Score, where StudentID is a string of no more than 20 English letters and digits, and Score is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).
Output Specification:
For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format: StudentID Gp Gmid-term Gfinal G If some score does not exist, output “-1” instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID’s. It is guaranteed that the StudentID’s are all distinct, and there is at least one qualified student.
对于在中国大学MOOC(http://www.icourse163.org/) 学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 G = (G期中x 40% + G期末x 60%),如果 G期中 > G期末;否则总评 G 就是 G期末。这里 G期中 和 G期末 分别为学生的期中和期末成绩。 现在的问题是,每次考试都产生一张独立的成绩单。本题就请你编写程序,把不同的成绩单合为一张。
输入格式:
输入在第一行给出3个整数,分别是 P(做了在线编程作业的学生数)、M(参加了期中考试的学生数)、N(参加了期末考试的学生数)。每个数都不超过10000。 接下来有三块输入。第一块包含 P 个在线编程成绩 G编程;第二块包含 M 个期中考试成绩 G期中;第三块包含 N 个期末考试成绩 G期末。每个成绩占一行,格式为:学生学号 分数。其中学生学号为不超过20个字符的英文字母和数字;分数是非负整数(编程总分最高为900分,期中和期末的最高分为100分)。
输出格式:
打印出获得合格证书的学生名单。每个学生占一行,格式为: 学生学号 G编程 G期中 G期末 G 如果有的成绩不存在(例如某人没参加期中考试),则在相应的位置输出“-1”。输出顺序为按照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。题目保证学号没有重复,且至少存在1个合格的学生。
给定一个 k+1 位的正整数 N,写成 ak…a1a0 的形式,其中对所有 i 有 0 <= ai < 10 且 ak > 0。N 被称为一个回文数,当且仅当对所有 i 有 ai = ak-i。零也被定义为一个回文数。 非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个非回文数可以变出回文数,就称这个数为延迟的回文数。(定义翻译自https://en.wikipedia.org/wiki/Palindromic_number) 给定任意一个正整数,本题要求你找到其变出的那个回文数。
输入格式:
输入在一行中给出一个不超过1000位的正整数。
输出格式:
对给定的整数,一行一行输出其变出回文数的过程。每行格式如下
A + B = C
其中A是原始的数字,B是A的逆转数,C是它们的和。A从输入的整数开始。重复操作直到C在10步以内变成回文数,这时在一行中输出“C is a palindromic number.”;或者如果10步都没能得到回文数,最后就在一行中输出“Not found in 10 iterations.”。
输入样例 1:
97152
输出样例 1:
97152 + 25179 = 122331 122331 + 133221 = 255552 255552 is a palindromic number.
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal sequence of the corresponding binary tree.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<=50000), the total number of nodes in the binary tree. The second line gives the preorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the first number of the postorder traversal sequence of the corresponding binary tree.
intfind(int inl, int inr, int x){ for (int i = inl; i <= inr; i++) { if (in[i] == x) return i; } return-1; }
voidprintPost(int pl, int pr, int inl, int inr, int n){ if (pl > pr || isOuput) return; int inRoot = find(inl, inr, pre[pl]); printPost(pl + 1, pl + inRoot - inl, inl, inRoot - 1, n); printPost(pl + inRoot - inl + 1, pr, inRoot + 1, inr, n); if (!isOuput) { printf("%d", in[inRoot]); isOuput = true; } }
intmain(){ int n = 0; scanf("%d", &n); pre = newint[n]; in = newint[n]; for (int i = 0; i < n; i++) { scanf("%d", &pre[i]); } for (int i = 0; i < n; i++) { scanf("%d", &in[i]); } printPost(0, n - 1, 0, n - 1, n); delete[] pre; delete[] in; return0; }