
+ 基础算法
文章平均质量分 74
codekun
这个作者很懒,什么都没留下…
展开
-
ZOJ 3326 - An Awful Problem
题意:给定一个日期范围,判断月和日均为素数的天数。比较水的题目,for循环中的?:判断语句、日期的打表,可以大幅精简代码。#include #include using namespace std;int day1[15] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //闰年int day2[15] = {0,原创 2015-04-10 16:56:07 · 513 阅读 · 0 评论 -
UVA - 725 Division
Division Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is原创 2014-12-12 23:05:12 · 627 阅读 · 0 评论 -
HDUOJ - 1316 How Many Fibs?
How Many Fibs?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4592 Accepted Submission(s): 1803Problem DescriptionRecall the defi原创 2014-12-18 23:41:41 · 444 阅读 · 0 评论 -
HDUOJ - 2054 A == B ?
Problem DescriptionGive you two numbers A and B, if A is equal to B, you should print "YES", or print "NO". Inputeach test case contains two numbers A and B. Outputfor each case, i原创 2014-12-21 14:26:14 · 591 阅读 · 0 评论 -
UVa 1587 - Box
这道题思路明确了还是不难的,关键是判断方法。首先正方体有三种不同的边,我们记为abc,并且记a>b>c,则长方体的六个面必定是ab、ab、ac、ac、bc、bc(按照边的长度排序),符合这种形式的就是一个正方体。根据题目叙述,重点是怎样把输入的数据转化为这种标准形式,然后进行判断。首先把每个面的两条边大小弄清楚,如ba转换为ab,即长>宽;然后对六个面进行排序,按照长从大到小排序,原创 2015-02-10 13:09:01 · 6465 阅读 · 3 评论 -
UVa 1596 - Bug Hunt
这道题太欠抽了,做了N次,每次做到一半的时候就感觉思路完全不对,然后就全删了重做。最后这次,交上一次AC了。题目本身,分为定义和赋值两部分,其中赋值又分为左右两部分,左边的内层和右边需要递归求出值来,左边外层直接赋值即可。这道题就是考察STL的字符串。前两天学习了Python,今天用STL的string感觉特别蛋疼,int和string的相互转换还这么麻烦,还好UVa支持C++11,还有字原创 2015-02-25 15:43:39 · 702 阅读 · 0 评论 -
SDUSTOJ T1581 Average Number
Average NumberTime Limit: 1 Sec Memory Limit: 128 MDescriptionPlease calculate the average number of the given n numbers without doing calculations of addition, multiplication, or division,原创 2014-10-04 11:13:30 · 436 阅读 · 0 评论 -
UVA 12108
Extraordinarily Tired StudentsTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionWhen a student is too tired, he can原创 2014-11-05 21:38:53 · 832 阅读 · 0 评论 -
UVA - 1591 Data Mining
Dr. Tuple is working on the new data-mining application for Advanced Commercial Merchandise Inc. One of the subroutines for this application works with two arrays P and Q containing N records of dat原创 2014-11-29 20:22:57 · 1299 阅读 · 0 评论 -
UVA - 540 Team Queue
书上的代码交上去Runtime Error,故按照自己的思路重写了#include using namespace std;int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);#endif int t, cnt原创 2014-12-01 16:59:22 · 564 阅读 · 0 评论 -
UVA - 10976 Fractions Again?!
Problem A: Fractions Again?!Time limit: 1 secondIt is easy to see that for every fraction in the form (k > 0), we can always find two positive integers x and y, x ≥ y, such th原创 2014-12-12 23:38:58 · 556 阅读 · 0 评论 -
HDUOJ - 1063 / POJ - 1001 Exponentiation
ExponentiationTime Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7275 Accepted Submission(s): 2072Problem DescriptionProblems involvi原创 2014-12-18 22:58:19 · 526 阅读 · 0 评论 -
UVaOJ 1339 - Ancient Cipher
Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form t原创 2014-10-20 17:01:47 · 485 阅读 · 0 评论 -
UVaOJ 1368 - DNA Consensus String
Figure 1.DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of four different nucleotides, namely Adenine, Thymine, Guanine, and Cytosine as shown in Fi原创 2014-10-17 21:45:58 · 524 阅读 · 0 评论 -
UVA 1586 ----Molar mass
这个题,走了不少弯路,做了之上2个小时,究其原因,化学功底不深厚啊。。。。。原创 2014-10-16 18:26:50 · 738 阅读 · 0 评论 -
HDU 1029 - Ignatius and the Princess IV
题意:给定N个数,选出其中数量大于(N+1)/2的数两种方法实现,第一种方法排序,选择中间的那个数。第二种方法搜一遍。#include #include #include #include #include using namespace std;int a[1024000];int main(){ int n; while(cin >> n){原创 2015-04-10 15:10:42 · 438 阅读 · 0 评论 -
UVa 1611 - Crane [构造法]
这道题有点像翻煎饼那题,方法不限,只要次数在9^6之内即可。从前到后依此选择数,最多只需要两次就可以将每个数放到正确位置。#include using namespace std;int a[10240];void change(const int l, const int r){ for(int i = l, j = l+(r+1-l)/2; j <= r; ++i,原创 2015-03-25 14:32:00 · 613 阅读 · 0 评论 -
UVa 11093 - Just Finish it up
循环遍历数组即可,注意临界条件的判断。#include using namespace std;const int maxn = 102400;int p[maxn], q[maxn];int main(){ //freopen("in.txt", "r", stdin); int T; cin >> T; for(int t = 1; t <= T; +原创 2015-03-13 17:25:57 · 531 阅读 · 0 评论 -
UVa 11925 - Generating Permutations
这题用了冒泡排序的思想,不过紫书上的描述有误,建议参考原题。#include using namespace std;deque a;vector res;bool is_order(){ for (int i = 1; i != a.size(); ++i) if (a[i] < a[i-1]) return false; return true;}int ma原创 2015-03-19 17:26:54 · 874 阅读 · 0 评论 -
UVa 1641 - ASCII Area
比较水的一题,找到方法就好说了。#include using namespace std;char tab[128][128];int main(){ int h, w; while (cin >> h >> w){ cin.get(); for (int i = 0; i < h; ++i ) cin >> tab[i]; int cnt = 0; for原创 2015-03-03 22:51:49 · 502 阅读 · 0 评论 -
UVa 294 - Divisors
基础题,就用基本方法即可,计算约数时算到sqrt(n)即可,要注意(int)sqrt(n)和n的关系。#include #include #include using namespace std;int main(){ int T; cin >> T; while (T--){ int L, U; cin >> L >> U; int MAX = -1, num;原创 2015-03-03 16:06:38 · 703 阅读 · 0 评论 -
UVa 246 - 10-20-30 [STL应用]
这道题在数据结构这一章里算是简单的,但是很容易WA和RE,可能得debug很长时间。值得注意的地方:1.纸牌被处理的次数中,每次发牌并且检查一次匹配,算处理一次,而不是四次2.查看匹配的时候,如果一次匹配成功并且删除了三张纸牌,要继续检查是否匹配,这是个循环的过程3.可以通过用set记录State判重,判断打平的情况4.纸牌收回手中时,注意纸牌摆放的顺序#include原创 2015-03-01 10:41:04 · 744 阅读 · 0 评论 -
UVA201 Squares
Squares A children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count原创 2014-10-29 15:16:20 · 605 阅读 · 0 评论 -
UVA 815 Flooded!
Flooded! To enable homebuyers to estimate the cost of flood insurance, a real-estate firm provides clients with the elevation of each 10-meter by 10-meter square of land in regions where homes may be原创 2014-11-11 23:39:23 · 501 阅读 · 0 评论 -
HDUOJ - 1715 大菲波数
Problem DescriptionFibonacci数列,定义如下:f(1)=f(2)=1f(n)=f(n-1)+f(n-2) n>=3。计算第n项Fibonacci数值。 Input输入第一行为一个整数N,接下来N行为整数Pi(1 Output输出为N行,每行为对应的f(Pi)。 Sa原创 2014-12-20 09:05:17 · 473 阅读 · 0 评论 -
HDU - 1032 The 3n + 1 problem
#include #include #include #include using namespace std;long long int table[1024000];void init(void){ for(long long int i=1; i<1000005; i++) { long long int x = i; lon原创 2015-01-05 23:33:45 · 439 阅读 · 0 评论 -
HDU - 2057 A + B Again
DescriptionThere must be many A + B problems in our HDOJ , now a new one is coming. Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.原创 2014-12-24 09:24:06 · 494 阅读 · 0 评论 -
UVA - 220 - Othello
最害怕这种下棋的题了,情况特别多,考差细节特别多,当时没做,现在翻过头来再看一下,顺便复习一下基础。这道题要注意格式,输出统计黑白棋子数的时候,数要占两位。其他都是普通的思路,顺着题目要求即可。寒假刚刚开始,是提高自我的好时间,希望自己能利用起来。#include using namespace std;char tab[10][10];const int dir[8]原创 2015-01-26 10:37:50 · 2399 阅读 · 2 评论 -
UVa 511 - Do You Know the Way to San Jose? [STL应用]
这题不难,但细节比较多,排序的依据有很多,比较容易出错。考差C++和STL也比较全面,比如结构体、构造函数、map、pair、vector、sort、unique、copy等等,使用C++11的lambda配合泛型算法是一个很好的选择。#include #define EPS 1e-7using namespace std;struct MAP{ string name; dou原创 2015-02-27 12:13:07 · 1192 阅读 · 0 评论 -
UVA 508 Morse Mismatches
Morse Mismatches Samuel F. B. Morse is best known for the coding scheme that carries his name. Morse code is still used in international radio communication. The coding of text using Mor原创 2014-11-29 18:44:46 · 2640 阅读 · 0 评论 -
HDUOJ - 1047 Integer Inquiry
Integer InquiryTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13470 Accepted Submission(s): 3382Problem DescriptionOne of the fi原创 2014-12-18 22:09:28 · 548 阅读 · 0 评论 -
UVa 1589 - Xiangqi <细节基础题>
这个题,三个月前写了一次,当时写道200行的时候,就感觉恶心了,当时感觉再写100行也完不成。今天拿出这题来重写了,尽量精简代码,结果没想到90行就AC了。精简代码的好处之一便是方便调试,因为细节太多了,把很多相似的内容放在函数中就好了。看似四个棋子的走法不同,实则有一个共同点:都需要判断棋子和“将”所在的行或者列中,两个棋子之间的棋子数。对于“帅”和“车”,之间的棋子数必须为0。对于炮,原创 2015-01-31 14:12:13 · 954 阅读 · 5 评论 -
UVa 12412 - A Typical Homework
这题做了两个月,是第四章最后一个AC的题,小细节比较多,仅样例的输出就一百多行,无奈借助专业的ultracompare才完成了对比,最后找到汝佳老师的源代码改了一个小细节AC了。注意的地方有:精度的控制;人数为0时平均分的输出;增加人员的时候,同名的人如果被移除了也可以添加。#include using namespace std;const double EPS = 1e-5;c原创 2015-02-14 11:20:30 · 1590 阅读 · 1 评论 -
SDUSTOJ T1587 YES! YOU CAN!
YES! YOU CAN!Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 44 Solved: 9[Submit][Status][Web Board]DescriptionTwo polar bears Menshykov and Uslada from the St.Petersburg zoo and elephan原创 2014-10-04 10:55:14 · 592 阅读 · 0 评论 -
UVA 1585 - Score
There is an objective test result such as ``OOXXOXXOOO". An `O' means a correct answer of a problem and an `X' means a wrong answer. The score of each problem of this test is calculated by itself an原创 2014-10-16 21:37:24 · 573 阅读 · 0 评论 -
UVA 1590 IP Networks
DescriptionAlex is administrator of IP networks. His clients have a bunch of individual IP addresses and he decided to group all those IP addresses into the smallest possible IP network.Each原创 2014-11-07 21:04:22 · 3603 阅读 · 2 评论 -
UVa 1593 Alignment of Code
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is basically a text editor with bells and whistles. You are working on a module that takes a piece of原创 2014-11-22 18:27:05 · 3146 阅读 · 2 评论 -
UVA - 230 Borrowers
Borrowers I mean your borrowers of books - those mutilators of collections, spoilers of the symmetry of shelves, and creators of odd volumes.- (Charles Lamb, Essays of Elia (1823) `T原创 2014-11-30 08:54:04 · 1009 阅读 · 0 评论 -
UVA - 11059 Maximum Product
Problem D - Maximum ProductTime Limit: 1 secondGiven a sequence of integers S = {S1, S2, ..., Sn}, you should determine what is the value of the maximum positive product involving consecut原创 2014-12-12 23:18:44 · 537 阅读 · 0 评论 -
HDUOJ - 1027 Ignatius and the Princess II
Problem DescriptionNow our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero firs原创 2014-12-20 09:23:47 · 496 阅读 · 0 评论