Posts
2015
poj 3481 double queues
http://acm.hdu.edu.cn/showproblem.php?pid=1908
看到有两个优先级,然后题目中又有queue。。。就想到了优先队列。。。
poj 1833 排列
http://poj.org/problem?id=1833
还是next_permutation.
这次是Int类型的
需要注意的是next_permutation是先判断时候有后继,返回一个bool值,如果为true,就转化到后继。
poj 1256 Anagram
http://poj.org/problem?id=1256
题意是说求出一个字符串的全排列,按字典序
需要注意的是字典序和传统意义上的字典序不同
codeforces 548B Mike and Fun
·1 min
http://codeforces.com/problemset/problem/548/B
比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。
codeforces 548 A. Mike and Fax
http://codeforces.com/problemset/problem/548/A
水题。分割成K个,每个串判断是否回文,如果都是就yes,否则no
poj 2492 A Bug's Life (并查集)
http://poj.org/problem?id=2492
Hint
Huge input,scanf is recommended.
也是带种类的冰茶几。
由于只分了两类…我们还是可以按照上道题的做法。。
poj 1703 Find them, Catch them (并查集)
http://poj.org/problem?id=1703
种类冰茶几…看到还有一种算是拓展的交加权冰茶几? 看到有做法是在开一个数组。。。记录是哪一组…. 但是因为只有两组….我们可以分别存… 因为不知道每一个D的两个人分别是哪个组(帮派?) 可以都存一下。 TLE了两次….应该是用了cin的事。。。改成scanf就变WA了。。。 想了下。原来是我对“not sure yet”的判断出现失误。 我开了一个v数组,记录在D下出现的人。 我误以为出现的人的帮派一定是确定的。 实际上并不是。 比如 1,3 5,7 3和7都出现了。但是3和7是一组与否显然还是“not sure yet”
codeforces 535 C.Tavas and karafs (解方程)
http://codeforces.com/problemset/problem/535/C
题读了好几遍才读懂。 题意是给出一个等差数列,操作严格要求从最左边不为零的连续m个数减去1,最多执行t次后问离最左边最远的位置在哪里。 有两个限制条件…一个是本身的si不能大于t,否则无法吃完。 还有一个是从sl到sr的和不能超过m*t (比赛的时候考虑的不周到。。实际上只有当r-l+1比m大的时候才是m,也就是说要取min(m,l-r+1)) 这题正解应该是二分….直接Lower_bound。。。看到也有人用前缀和搞的。 我是解方程了(貌似是个傻逼做法)…. 可以列出一个关于r的一元二次方程。。。然后求根公式2333 方程是:
codeforces 534 C Polycarpus' Dice
http://codeforces.com/problemset/problem/534/C
题意是说一共有N个骰子,第I个筛子一共有di面…现在知道这些骰子的点数之和,问对于每一个骰子不能取得值有多少个。
cf 534B. Covered Path
http://codeforces.com/problemset/problem/534/B
题意是说一辆车,每秒内的速度恒定…第I秒到第I+1秒的速度变化不超过D。初始速度为V1,末速度为V2,经过时间t,问最远能走多远。
cf 535B Tavas and SaDDas
B. Tavas and SaDDas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn’t stop doing that. That’s why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas’ headphones and told him: “If you solve the following problem, I’ll return it to you.”
codeforces 534 A. Exam
A. Exam
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.
codeforces 479D. Long Jumps
·2 mins
http://codeforces.com/problemset/problem/479/D
题意是说有一把尺子,本身有一些刻度,然后需要测量x和y,问最少需要添加多少个刻度,如果需要,这些刻度分别添加在什么位置。
codeforces 525 B. Pasha and String
http://codeforces.com/problemset/problem/525/B
1题意是说一个字符串,进行m次颠倒变换(从a[i]位置到a[l-i+1]位置),问得到的字符串。容易发现,对于越在里边(对称,也就是越靠近中间位置)的字符,调换的次数越多。我们可以把a[i]从小到大排序。然后经过分析发现,把两个相邻的a[i]分为一组,做处理,如果m为奇数,最后还剩下a[m]没有被分组,要单独处理a[m]细节上要注意st数组是从st[0]开始的...好吧的确不方便,适牛也说我了。。数组下标以后还是从0开始吧。。。主要是受高中OI用的pascal的影响。。。那个数组下标随便啊。代码: 2 3 4 5 6 /* *********************************************** 7 Author :111qqz 8 Created Time :2016年02月22日 星期一 23时39分51秒 9 File Name :code/cf/problem/525B.cpp 10 ************************************************ */ 11 12 #include <iostream> 13 #include <algorithm> 14 #include <cstring> 15 #include <cmath> 16 #include <cstdio> 17 18 using namespace std; 19 20 int m,k,len; 21 const int N=2E5+7; 22 int a[N]; 23 char st[N]; 24 25 int main() 26 { 27 cin>>st; 28 scanf("%d",&m); 29 for ( int i = 1 ; i <= m ; i++ ) 30 scanf("%d",&a[i]); 31 sort(a+1,a+m+1); 32 k = 1; 33 len = strlen(st); 34 while (k<=m) 35 { 36 for ( int j = a[k] ; j <= a[k+1]-1 ; j++) 37 swap(st[j-1],st[len-j]); 38 k = k + 2; 39 } 40 if ( m %2==1 ) 41 for ( int i = a[m]; i <= len/2 ; i++ ) 42 swap(st[i-1],st[len-i]); 43 cout<<st<<endl; 44 return 0; 45 }
codeforces 482 A. Diverse Permutation(构造)
C - C
**Time Limit:**1000MS **Memory Limit:**262144KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Permutation_p_ is an ordered set of integers _p_1, p_2, …, p__n, consisting of n distinct positive integers not larger than n. We’ll denote as_n the length of permutation _p_1, _p_2, …, p__n.
codeforces 47 C. Exams
http://codeforces.com/problemset/problem/479/C
1/************************************************ 2Author :111qqz 3Created Time :2016年02月22日 星期一 23时31分10秒 4File Name :code/cf/problem/479C.cpp 5************************************************ */ 6 7#include <iostream> 8#include <algorithm> 9#include <cstring> 10#include <cstdio> 11 12#include <cmath> 13 14using namespace std; 15int n,ans; 16const int N=1E4+5; 17int a[N],b[N]; 18 19struct Q 20{int a,b; 21}q[N]; 22 23bool cmp(Q x, Q y) 24{ 25 if ( x.a<y.a) return true; 26 if ( x.a==y.a &&x.b<y.b ) return true; 27 return false; 28} 29 30int main() 31{ 32 scanf("%d",&n); 33 for ( int i = 1 ; i <= n ; i++ ) 34 scanf("%d %d",&q[i].a,&q[i].b); 35 sort(q+1,q+n+1,cmp); 36 37 ans=q[1].b; 38 for ( int i = 2 ; i <= n; i++ ) 39 { 40 if ( q[i].b>=ans ) 41 ans = q[i].b; 42 else ans = q[i].a; 43 } 44 printf("%d\n",ans); 45 return 0; 46}
hdu 1160 FatMouse's Speed (最长上升子序列)
FatMouse’s Speed # Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10172 Accepted Submission(s): 4521 Special Judge
hdu 1260 tickets
Tickets # **Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1408 Accepted Submission(s): 687 **
hdu 1176 免费馅饼(二维dp)
免费馅饼 # **Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29065 Accepted Submission(s): 9921 **