hdu 4810 Wall Painting 位操作
本题题意甚是费解。
找到合适的位操作,再运用组合数,是关键。
1 | /** |
本题题意甚是费解。
找到合适的位操作,再运用组合数,是关键。
1 | /** |
遇到本题,在对象成员中申请数组空间的话,会不明就里地TLE,而且浪费大量内存。
1 | /** |
过于傻气的递推公式!
状态傻傻分不清楚
写矩阵乘法,混淆了左乘与右乘。
1 | /** |
1 | /** Aug 24, 2015 11:15:57 AM |
折腾了过长的时间,原因:
这不是通常意义上的可随意匹配的二分图。
既然是二分图,就有把节点分为两类的依据。
由题中给定的结合规则,一定是一个(x+y)为偶数的点与一个(x+y)为奇数的点相匹配,且是相邻点的匹配。
所以会将两类点分别加入两个表中,并进行hash操作节约存储空间。
“奇”的点总是不少于“偶”的点?
Description
Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long board just long enough to saw into the N planks (i.e., whose length is the sum of the lengths Li). FJ is ignoring the “kerf”, the extra length lost to sawdust when a sawcut is made; you should ignore it, too.
FJ sadly realizes that he doesn’t own a saw with which to cut the wood, so he mosies over to Farmer Don’s Farm with this long board and politely asks if he may borrow a saw.
Farmer Don, a closet capitalist, doesn’t lend FJ a saw but instead offers to charge Farmer John for each of the N-1 cuts in the plank. The charge to cut a piece of wood is exactly equal to its length. Cutting a plank of length 21 costs 21 cents.
Farmer Don then lets Farmer John decide the order and locations to cut the plank. Help Farmer John determine the minimum amount of money he can spend to create the N planks. FJ knows that he can cut the board in various different orders which will result in different charges since the resulting intermediate planks are of different lengths.Input
Line 1: One integer N, the number of planks
Lines 2..N+1: Each line contains a single integer describing the length of a needed plankOutput
Line 1: One integer: the minimum amount of money he must spend to make N-1 cutsSample Input
3
8
5
8Sample Output
34Hint
He wants to cut a board of length 21 into pieces of lengths 8, 5, and 8.
The original board measures 8+5+8=21. The first cut will cost 21, and should be used to cut the board into pieces measuring 13 and 8. The second cut will cost 13, and should be used to cut the 13 into 8 and 5. This would cost 21+13=34. If the 21 was cut into 16 and 5 instead, the second cut would cost 16 for a total of 37 (which is more than 34).
犯过以下错误:
误用二分
元素删除后未完成堆的调整操作
最小堆写成了最大堆
long类型的res用了int类型
1 | import java.io.*; |
- Problem Description
Mike does not want others to view his messages, so he find a encode method Base64.
Here is an example of the note in Chinese Passport.
The Ministry of Foreign Affairs of the People’s Republic of China requests all civil and military authorities of foreign countries to allow the bearer of this passport to pass freely and afford assistance in case of need.When encoded by
Base64
, it looks as followsVGhlIE1pbmlzdHJ5IG9mIEZvcmVpZ24gQWZmYWlycyBvZiB0aGUgUGVvcGxlJ3MgUmVwdWJsaWMgb2Yg
Q2hpbmEgcmVxdWVzdHMgYWxsIGNpdmlsIGFuZCBtaWxpdGFyeSBhdXRob3JpdGllcyBvZiBmb3JlaWdu
IGNvdW50cmllcyB0byBhbGxvdyB0aGUgYmVhcmVyIG9mIHRoaXMgcGFzc3BvcnQgdG8gcGFzcyBmcmVl
bHkgYW5kIGFmZm9yZCBhc3Npc3RhbmNlIGluIGNhc2Ugb2YgbmVlZC4=In the above text, the encoded result of
The
isVGhl
. Encoded in ASCII, the charactersT
,h
, ande
are stored as the bytes84
,104
, and101
, which are the 8-bit binary values01010100
,01101000
, and01100101
. These three values are joined together into a 24-bit string, producing010101000110100001100101
.
Groups of 6 bits (6 bits have a maximum of2^6 = 64
different binary values) are converted into individual numbers from left to right (in this case, there are four numbers in a 24-bit string), which are then converted into their corresponding Base64 encoded characters.
The Base64 index table is
0123456789012345678901234567890123456789012345678901234567890123 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ In the above example, the string
010101000110100001100101
is divided into four parts010101
,000110
,100001
and100101
, and converted into integers21, 6, 33
and37
. Then we find them in the table, and get V, G, h, l.
When the number of bytes to encode is not divisible by three (that is, if there are only one or two bytes of input for the last 24-bit block), then the following action is performed:
Add extra bytes with value zero so there are three bytes, and perform the conversion to base64. If there was only one significant input byte, only the first two base64 digits are picked (12 bits), and if there were two significant input bytes, the first three base64 digits are picked (18 bits). ‘=’ characters are added to make the last block contain four base64 characters.
As a result, when the last group contains one bytes, the four least significant bits of the final 6-bit block are set to zero; and when the last group contains two bytes, the two least significant bits of the final 6-bit block are set to zero.
For example, base64(A) = QQ==, base64(AA) = QUE=.
Now, Mike want you to help him encode a string fork
times. Can you help him?
For example, when we encode A for two times, we will get base64(base64(A)) = UVE9PQ==.
Input
The first line contains an integer T(T≤20) denoting the number of test cases.
In the following T lines, each line contains a case. In each case, there is a number k(1≤k≤5) and a string s. s only contains characters whose ASCII value are from 33 to 126(all visible characters). The length of s is no larger than 100.Output
For each test case, output Case #t:, to represent this is t-th case. And then output the encoded string.Sample Input
2
1 Mike
4 MikeSample Output
Case #1: TWlrZQ==
Case #2: Vmtaa2MyTnNjRkpRVkRBOQ==
粗暴的模拟题,但是赛场上的做法简直一根筋;
修正……
1 | /** |
#D.Doom
本题的唯一(赛场上难以发现的)突破口就是,输入数据任给的正整数,经过不超过30次“平方再取模”操作后都成为某一定值。
也有特别的卡long long边界而不卡unsigned long long的现象,Java中不存在无符号类型因而无法实现。
#E.Exam
贪心。。。
1 | /** Sep 6, 2015 8:40:50 PM |
#F.Friends
必须及时通过必要的暴力模拟来找出这个千呼万唤不出来的规律
1 | /** |
#J.Joyful
赛场上耗费不少精力的题。。。
我无论是赛中还是赛后都没明白一点:对一个矩形区域涂色次数的期望,就是对该区域各点涂色期望之和。
写代码时轻视了多个int类型值相乘越界的问题
1 | /** Sep 6, 2015 9:26:29 PM |
#A.Article
赛中没有耐心读完的题。。。赛后还读错了题意……
原来按“保存”键是不存在失败率的,这大大简化了问题模型(即可列出状态转移方程)。
1 | /** Sep 7, 2015 6:37:43 PM |
1 | struct Edge |
来到如此遥远的地域挑战未知,少有惊喜却多有险阻。
第一个签到题D题的疏忽几乎引起我的疯狂WA。实际上只是简单的边界问题的处理(分数值等于0)胡牛和张学长的仔细列举检验奏效了。
我个人花大量精力为F题写的线段树惨烈地挂了。Lazy标记未能体现出应有的使用价值。多种不同的修改操作与统计操作的优先级,必是平时练习时漏洞密布之处。
E题简单的计算几何遭遇了一些磕绊。张学长所归纳的方程是正确的,只是计算过程中变量范围的设置不甚合理。
相比之下,A题递推的实现较为顺利。
I题和J题是既面熟又陌生的题型。尽管全队坚持到了最后一刻,却未能再争取关键的突破。
赛后听解题报告会,发现原题无不存在破解的可能性?
原题地址
比赛时卡在这种题上,很是要命
Edward the confectioner is making a new batch of chocolate covered candy. Each candy center is shaped as a cylinder with radius r mm and height h mm.
The candy center needs to be covered with a uniform coat of chocolate. The uniform coat of chocolate is d mm thick.
You are asked to calcualte the volume and the surface of the chocolate covered candy.
Input
There are multiple test cases. The first line of input contains an integer T(1≤ T≤ 1000) indicating the number of test cases. For each test case:
There are three integers r, h, d in one line. (1≤ r, h, d ≤ 100)
Output
For each case, print the volume and surface area of the candy in one line. The relative error should be less than 10^-8.
Sample Input
2
1 1 1
1 3 5Sample Output
32.907950527415 51.155135338077
1141.046818749128 532.235830206285Author: ZHOU, Yuchen Source: The 15th Zhejiang University Programming Contest
在底面半径r mm,高h mm的圆柱体糖块外裹上一层厚度均匀的壳,求它的体积和表面积。
设外壳厚度为$ a $ mm(只是为了避免与微分符号混淆,原题中用d表示),
(1)糖果顶上和底下的各一个侧面圆滑的类台体
$ z^2+{(y-r)}^2=a^2(y\ge r),y=\sqrt {a^2-z^2} +r.$
$$
\begin{array}
\newline
V_{台体}=\int_0^a{\pi (\sqrt {a^2-z^2} +r)^2 {\rm d}z}
\newline\left( 或V_{台体}=\int_0^a {\rm d}z\int_0^{2\pi}{\rm d}\theta \int_0^{r+a\sqrt{1-\frac{z^2}{a^2}}}r{\rm d}r \right)
\newline=\int_0^a \pi \left(r+a\sqrt{1-\frac{z^2}{a^2}}\right)^2 {\rm d}z
\newline=\int_0^a \left( \pi r^2+\pi a^2\left(1-\frac{z^2}{a^2}\right)+2\pi ar\sqrt{1-\frac{z^2}{a^2}} \right) {\rm d}z
\newline=\int_0^a \left( \pi r^2+\pi a^2 \right) {\rm d}z-\int_0^a \pi z^2{\rm d}z + \int_0^a 2\pi r\sqrt{a^2-z^2}{\rm d}z
\newline=\pi a^3+\pi ar^2-\frac{\pi a^3}{3}+\frac{\pi^2 a^2r}{2}\newline
\end{array}
$$
(2)糖果中部的圆柱体
$ V_{圆柱}=Sh=\pi r^2h=\pi(r+a)^2h$
(3)总体积
$ V=2V_{台体}+V_{圆柱}=\frac{4\pi a^3}{3}+2\pi ar^2+\pi^2a^2r+\pi(r+a)^2h $
(1)求上下各一个环状曲面的面积
这个曲面(轮胎面)的参数方程为
$$
\begin{cases}
x = (r+a {\rm cos}\varphi) {\rm cos}\theta \newline
y = (r+a {\rm cos}\varphi) {\rm sin}\theta \newline
z = a {\rm sin}\varphi
\end{cases}
$$
用向量值函数表示为:$ \vec{f}(\theta,\varphi)=x(\theta,\varphi)\vec{i}+y(\theta,\varphi)\vec{j}+z(\theta,\varphi)\vec{k}$
该曲面上某一点(x,y,z)处的基本法向量
$$
\vec{n}=(-\frac{\partial z}{\partial x},-\frac{\partial z}{\partial y},1)=\frac{\partial \vec{f}}{\partial \theta}\times\frac{\partial \vec{f}}{\partial \varphi}
$$
积分区域$ \Sigma=$ { $ \left(\theta,\varphi \right) | 0\le \theta \le 2\pi,0\le \varphi \le\frac{\pi}{2} $ }
$$
\begin{array}
\newline
S_{环}=\iint_\Sigma {\rm d}S=\iint_\Sigma |\vec{n}| {\rm d}x{\rm d}y\newline
=\iint_\Sigma \sqrt{\left(-\frac{\partial z}{\partial x}\right)^2+\left(-\frac{\partial z}{\partial y}\right)^2+1}{\rm d}x{\rm d}y\newline
=\iint_\Sigma \left|\frac{\partial \vec{f}}{\partial \theta}\times\frac{\partial \vec{f}}{\partial \varphi}\right| {\rm d}x{\rm d}y\newline
=\int_0^\frac{\pi}{2} {\rm d}\varphi \int_0^{2\pi} a(r+a {\rm cos}\varphi) {\rm d}\theta\newline
=\int_0^\frac{\pi}{2} 2\pi a(r+a {\rm cos}\varphi){\rm d}\varphi\newline
=2\pi a\left.(r+a {\rm cos}\varphi)\right|_0^\frac{\pi}{2}=\pi^2 ar+2\pi a^2\newline
\end{array}
$$
(2)求侧面积
$$
S_{侧}=2 \pi(r+a)h
$$
(3)求底面积
$$
S_{底}=\pi r^2
$$
(4)总表面积
$$
S=S_{环}+S_{侧}+2S_{底}=\pi^2 ar+2\pi a^2+2 \pi(r+a)h+2 \pi r^2
$$
刚开始,用最常规的输入输出:
import java.util.*; Scanner scan=new Scanner(System.in); System.out.println("...");
面对海量输入输出数据,TLE妥妥的
接着有了下面这种姿势(输入流?):
import java.util.*; import java.io.*; Scanner scan=new Scanner(new BufferedInputStream(System.in));
效果不太理想。
最后查阅大神用于处理水题的代码,获得以下终极模板:
import java.io.*; /*...*/ public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); while(in.nextToken() != StreamTokenizer.TT_EOF){ n=(long)in.nval; in.nextToken(); m=(long)in.nval; out.println(n+" "+m); } out.flush();//刷新。若本行放循环体内,则毎输入一组数据即输出一组答案,但是效率降低 out.close(); }