↓ Skip to main content

Posts

2016

codeforces 312 B. Archer

·565 words·2 mins
http://codeforces.com/problemset/problem/312/B # 题意:两个人比赛射箭,先射的人射中的概率是a/b,后射的人射中的概率是c/d,问先射的人赢的概率。 思路:应该叫条件概率。。。? 不过我们可以用古典概型的思维想。每射一次看成一个点,射中的点用白色表示,没有射中的用黑色表示。如果两个人第i次都没有射中,那么就要继续第i+1 轮,而第i+1轮和之前的每一轮是独立的。等于重复这个过程。所以古典概型的样本总量应该减去宝石两个人都没有射中的点的个数,为bd-(b-a)(d-c),整理为bc+ad-a*c,设为n.要想第一个人赢,那么对于某一次,只要不是第一个人没射中,第二个人射中这种情况,就都是第一个人赢。而第一个人没射中的事件数为b-a,第二个人射中的事件数为c,总数为(b-a)*c,所以答案为(n-(b-a)*c)/n

codeforces 453 A. Little Pony and Expected Maximum

·374 words·1 min
http://codeforces.com/problemset/problem/453/A 题意:m面骰子,每面点数出现的概率相同,连续投掷n次,问出现的最大值的数学期望。 思路:手写样例。。。发现答案为 。。。记得把(1/m)^n放进去。 观察答案,可以这样理解(我是用样例推出公式后理解。。。数学差的人心好累):如果i为最大值,那么n次每次必须投掷出1..i的点数,概率为 (i/m)^n,但是要至少有一个投掷成i,也就是要减去所有的数都是1..i-1中的情况(概率 为((i-1)/m)^n),

codeforces 476 B. Dreamoon and WiFi

·565 words·2 mins
http://codeforces.com/problemset/problem/476/B 题意:给出两个长度相等-且不超过10的字符串,串1只包含‘-’,’+‘。按照‘+’为1,‘-’为-1累加可以得到一个值。串2还包含若干‘?’,代表该处的值不确定,且为’+‘和’-‘的概率相等,都是0.5.问串2的值和串1相等的概率。 思路:我们可以扫一遍得到‘?’的个数和两个式子的差值。设问号个数为a,差值为b,那么在a个问号中需要有(a-b)/2个为‘+’(容易知道,a,b一定奇偶性相同,所以a-b一定能被2整除),根据超几何分布,概率为 c[a][(a-b)/2]*(1/2)^a; 写的时候可以先打个组合数的表。1A,开心。

codeforces #341 div2 A. Die Roll

·470 words·1 min
http://codeforces.com/contest/621/problem/A A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

codeforces #341 div 2 B. Wet Shark and Bishops

·607 words·2 mins
http://codeforces.com/contest/621/problem/B B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.

codeforces #341 div2 C. Wet Shark and Flowers

·1387 words·3 mins
http://codeforces.com/contest/621/problem/C C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too. Each shark will grow some number of flowers s__i. For i-th shark value s__i is random integer equiprobably chosen in range from _l__i_to r__i. Wet Shark has it’s favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product s__i·s__j is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.

uva 10916 Factstone Benchmark

·295 words·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1857 题意:计算最大的n,满足n!/* *********************************************** Author :111qqz Created Time :2016年01月29日 星期五 19时49分25秒 File Name :code/uva/10916.cpp ************************************************ */ #include #include #include #include #include #include #include #include #include #include #include #include #define fst first #define sec second #define lson l,m,rt«1 #define rson m+1,r,rt«1|1 #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair

uva 107 The Cat in the Hat

·440 words·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=43 题意:其实就是给了两个式子。。。(N+1)^h=a,N^h=b,a,b已知,然后求关于N的两个式子.。。 思路:数学上这个方程貌似不可解。。? 所以只能枚举一下==。。。注意精度问题把。。。

uva 846 Steps

·750 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=787 题意:从x增加到y,第一步和最后一步步长只能是1,其他步一定可以是上一步减一,和上一步相等,或者上一步步长加一,三种情况,且步长恒为正。问从x到y最少需要的步数。

uva 10025 The ? 1 ? 2 ? ... ? n = k problem

·421 words·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=966 题意:?1?2?3?4…?n=k,把每个?替换成+或者-,找到最小的n使得式子成立。 题意:这道题最关键的一点是。如果s1=1+2+3+.,x+..+n>=k (所有数取正数),那么一定有s2=1+2+3+..-x+..+n=k

uva 113 Power of Cryptography

·240 words·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=49 题意:求p开n次方。保证结果为整数。 思路:p最大10的101次方。。。double最大10的308次方。。因为肯定是整数。。不存在精度问题。。所以可以用double水过QAQ…

uva 10785 The Mad Numerologist

·753 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1726 题意:给出26个大写字母的权值,要求构造一个长度为n(n不超过210)的字符串。并且满足奇数位置只能放元音字母,偶数位置只能放辅音字母,且每个元音字母最多放21次,每个辅音字母最多放5次,要求构造的字符串的权值之和最小,在权值最小的前提下字典序最小。

uva 10194 Football (aka Soccer)

·768 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1135 题意:给出球队的名字和比赛的信息,得出standing 思路:字符串处理。需要注意的是多组数据记得初始化多次,以及比较字典序的时候team name是大小写不敏感的。

uva 156 - Ananagrams

·881 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=92 题意:给出一段文字,包含若干个单词,以’#‘结束。按照字典序输出所有的ananagrams。所谓ananagram,是指经过任意的重排后,不能得到这段文字中的另一个单词(不区分大小写) 思路:首先是字符串的读入…可以整行读入然后用空格分隔单词。由于补区分大小写,所以要都转化成小写…但是输出的时候要输出原始,所以还记得保留一份。而且要能够通过新的找到原始的(我用了一个toori的map<string,string>来实现) 然后最关键的部分是如何判断两个单词经过重排是否能一样…

uva 120 Stacks of Flapjacks

·634 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=56 题意:给出一个长度为n的序列(无重复元素),询问经过多少次flip(i)操作,使得序列升序排列。定义flip(i)为将1到n-i+1的元素反转… 思路:先离散化,然后注意读入….

uva 409 - Excuses, Excuses!

·589 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=350 题意:给出k个key word,e个借口…找出包含key word最多的借口,即为最坏的借口。匹配补区分大小写&&同一个key word算多次。 思路:需要注意的是因为不区分大小写,需要都转化成大写或者小写。。但是输出的时候要输出原始的。。所以要另外存一份。

hdu 5610 ||BC #69 div2 1001 Baby Ming and Weight lifting

·412 words·1 min
http://acm.hdu.edu.cn/showproblem.php?pid=5610 题意:有重量为a,b两种铁圈每种无限多个…能能否组成一个重量为c且平衡杠铃(中间的杆的重量忽略不计) a,b,c都是整数。 思路:平衡的话。。就是两边重量一样。。那么c为奇数的时候显然不行。 由于有多组答案的时候输出铁圈数之和小的。。。那么我们枚举的话。应该把里面那层枚举的变量放置成重量较大的。。。。

hdu 5611 || BC #69 div2 1002 Baby Ming and phone number

·757 words·2 mins
http://acm.hdu.edu.cn/showproblem.php?pid=5611 题意:给出n个电话号码(长度为11的字符串),满足特殊条件的价格为a,否则为b.特殊条件为最后5位数字一样,最后5位严格递增或者严格递减,最后8位是一个1980年1月一日到2016年12月31日的合法日期。问最后的价值。

uva 537 Artificial Intelligence?

·992 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=478 题意:给出一段文字,其中包含了 P,U,I(功率,电压,电流)中的两个,求第三个。 思路:字符串处理。第一次用vim复制整段代码,命令模式下按v,然后光标扫过的区域都会选中,按y就复制到剪贴板了。 所以虽然代码写了300行但只有100行是需要写的,200行复制改下就好== WA了两次,一次是因为I写成了小写,另一次是因为多组数据记得初始化多次。

uva 10010 - Where's Waldorf?

·1007 words·3 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951 题意:给出一个由大小写字母组成的二维maze…给出k个询问。每个询问一个单词。问能否在maze中找到这个单词。不区分大小写。输出开头字母的坐标(从1开始)。如果有多组输出最上面的。如果还有多组,输出最左边的。数据保证至少有一组。 思路:直接找就好了。坑的地方是格式:数据组数之后会有一个空行,然后每两组读入数据之间会有一个空行,输出的时候每两组数据之间也有一个空行。