- 博客(24)
- 收藏
- 关注
原创 UVa11732strcmp() Anyone?
今天学了Trie,觉得自己要学的东西实在太多了这一题的思路刘汝佳的书上有,一边插入一边计算,每个节点记录经过此处的字符串的数量,边插边加,计算的时候注意要考虑全面,注意插入字符串的第一个节点(比较时首字母就不同),中间的节点,和最后的节点(即字符串相同),看图:例一的情况就是首字母不同:答案的计算过程就是1+2(节点0)例二的情况就是中间的情况:答案的计算过程就是1+2+3(节
2013-08-28 22:18:02 771
原创 LA3266Tian Ji -- The Horse Racing
WA了一晚上。。看的别人的思路才过的TAT!!!!思路就是先对两人的马进行排序,比较当前两人最烂的马,如果田忌赢,那就直接拿下,否则再比较最叼的马,如果田忌赢,那么就直接拿下,否则就让田忌当前最烂的马输(也有可能平局)#include #include #include #include #include using namespace std;const int maxn = 100
2013-08-27 11:40:22 599
原创 UVa11136 - Hoax or what
水题:multiset搞定#include #include #include #include using namespace std;multiset S;multiset::iterator it;int main(){ int n; while(~scanf("%d",&n) && n){ S.clear(); int ans = 0; while(n--
2013-08-26 22:03:43 580
原创 UVa11988-Broken Keyboard (a.k.a. Beiju Text)
水题,STL lis模拟 直接1A#include #include #include #include #include using namespace std;int main(){ string st; list Li; list::iterator it; while(getline(cin,st)){ Li.clear(); Li.push_back("");
2013-08-26 17:02:13 615
原创 UVa11987 Almost Union-Find
构造虚拟的父亲节点 1-10001 2-10002.....可以看出这样构造的话1,2,3.,n不会成为父亲节点。也就不会出现指向不明的情况#include #include #include using namespace std;const int maxn = 100000;int father[2*maxn+10],rank[maxn+10],sum[maxn+10];v
2013-08-26 10:43:39 522
原创 KM
今天练的KM算法POJ2195 裸的,只不过要把正权改成负权#include #include #include using namespace std;const int maxn = 555;const int inf = 1000000000;int w[maxn][maxn],x[maxn],y[maxn];int prev_x[maxn],prev_y[maxn],
2013-08-22 15:24:39 676
原创 Uva11500-Gambler's ruin
Gambler's ruin(马尔科夫过程的一个实例)//Gambler's ruin#include #include #include #include using namespace std;int main(){ int v1,v2,at,d; while(~scanf("%d%d%d%d",&v1,&v2,&at,&d) && v1+v2+at+d){ int
2013-08-19 10:25:58 791
原创 Uva872-Ordering
排列组合问题,stl的next_permutation搞定#include #include #include #include #include #include using namespace std;const int maxn = 100;bool mat[maxn][maxn];int main(){ int ncase; cin >> ncase; ge
2013-08-17 23:42:36 541
原创 Uva11129-An Antiarithmetic Permutation
分治:按着网上的思路写的#include #include #include #include using namespace std; int n;vector aa,bb;void init(){ aa.clear(); aa.resize(n); bb.clear(); bb.resize(n); for(int i = 0; i < n; i++){ bb[
2013-08-15 21:55:19 644
原创 Uva11572-Unique Snowflakes
统计最长无公共元素子串:map 搞定#include #include #include #include #include #include using namespace std;int n;vector st;map visit;void LNRS_dp_hash_impro(vector &arr, int size){ //memset(visit, -1,
2013-08-15 21:53:57 649
原创 Uva10245-The Closest Pair Problem
最近点对问题:模板题#include #include #include #include #include #include using namespace std;#define eps 1e-6const int maxn = 10000+10;struct node{ double x,y;};int n,ss[maxn];double ans;node a
2013-08-15 21:51:42 664
原创 Uva11076-Add Again
简单的排列组合题:英语差一开始在纠结这个digit的意思,后来知道digit是一位数的意思,做法很简单,就是统计每个数的个数,用map记录,如1112,1的个数是3,2的个数是1。z最后计算的时候除去个数的阶乘即可。#include #include #include #include #include #include using namespace std;#define ULL
2013-08-10 12:37:42 731
原创 LA2756--Crazy tea party
规律题:被n=2的这种情况坑了!#include #include #include using namespace std;int main(){ vector dd; dd.push_back(0); dd.push_back(0); dd.push_back(1); for(int i = 2; i <= 17000; i++){ int tmp = ((i+1)*
2013-08-08 16:28:58 641
原创 Uva11461 Square Numbers
水题:upper_bound,lower_bound解决问题#include #include #include #include #include using namespace std;int main(){ int a,b; vector squ; vector::iterator low,up; for(int i = 1; i <= 1000; i++){
2013-08-07 23:15:40 569
原创 Uva11489 Integer Game
#include #include #include #include using namespace std;int main(){ int ncase,T=1; cin >> ncase; string num; while(ncase--){ cin >> num; int sum = 0; int a=0,b=0,c=0; bool flag = 0;
2013-08-07 22:51:03 634
原创 Uva11609 teams
主要是公式的推导和快速幂的使用,弹了一次,因为交大出的那本SCL快速幂的模板有点小错误#include #include #include using namespace std;long long pow_mod(long long a,long long i,long long n){ if(i == 0) return 1%n; long long tmp = pow_m
2013-08-07 20:42:13 682
原创 Uva11752 The Super Powers
简单的数论题:主要的注意点是计算幂的时候尽量少用pow,精度损失太大。#include #include #include #include #include #include #include #include using namespace std;const int maxn = 100 + 10;bool vis[maxn];map mm;vectorans;vo
2013-08-06 22:24:46 694
原创 Uva10780 Again Prime? No Time.
这题搞了1个多小时= =!靠着UVA的BBS上的数据才过的 思路是:把m质因数分解,各质因数的系数用map(a)记录,把1到n的数都质因数分解,用map(b)记录(累加),然后逐一遍历,碰到a[i]=0则跳过,碰到b[i] = 0& a[i]!= 0 则无解,接下来就是我无法理解地方了,判断前两种情况之后,如果碰到b[i] 无法整除a[i] 的时候,理应是无解,但是我只要这样判 就是WA,如果不判
2013-08-05 22:14:17 726
原创 Uva10905 Children's Game
坑题:很容易想错,用的是贪心的思想,对字符串进行排序,输出即可,主要是cmp函数的构造坑点1: 90 和 9#include #include #include #include using namespace std;bool comp(string a,string b){ int i; while(a.size() > b.size()){ for(i = 0;
2013-08-05 15:30:16 525
原创 uva11889 Benefit
思路与uva10892类似#include #include #include using namespace std;long long gcd(long long a,long long b){ return b == 0 ?a : gcd(b,a%b);}int main(){ int ncase; vector num; cin >> ncase; while(n
2013-08-04 22:46:25 662
原创 Uva10892 LCM Cardinality
基础的数论题:对n进行因式分解,因为两个数的LCM一定是LCM的因数。根据公式a*b = lcm(a,b)*gcd(a,b) 判断a,b是否为所求。#include #include #include #include using namespace std;int gcd(int a,int b){ return b == 0 ? a : gcd(b,a%b);}int main
2013-08-04 16:14:00 734
原创 Uva10970 Big Chocolate
水水题#include #include using namespace std;int main(){ int m,n; while(~scanf("%d%d",&m,&n)){ cout<<(n-1)*m+m-1<<endl; } return 0;}
2013-08-03 12:55:52 552
原创 Uva 10340 ALL IN ALL
弱爆了,这种水题都能弹个几次。。。少了一个++k #include #include #include #include #include using namespace std;int main(){ string st1,st2; while(cin >> st1 >> st2){ int k = 0,cnt = 0; for(int i = 0; i < s
2013-08-03 12:43:01 483
原创 Uva11039 Building design...
水题:根据绝对值大小排序,遍历即可#include #include #include #include using namespace std;struct num{ int val,symbol; friend bool operator <(num a,num b){ return a.val<b.val; }};int main(){ int ncas
2013-08-01 11:45:40 562
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人