
UVA
BEconfidence
坚持才是胜利之道
展开
-
uva12657 boxes in a line
#include#includeusing namespace std;const int N = 100005;int le[N], ri[N], n, m;typedef long long ll;void link(int l, int r)//链接l和r,l在左边{ le[r] = l; ri[l] = r;}int main(){ int cas =原创 2015-01-31 22:30:35 · 887 阅读 · 0 评论 -
uva122 trees on the level
看不下去,找点简单的,再回来写原创 2015-01-31 23:17:51 · 550 阅读 · 0 评论 -
uva679 dropping balls
#include#includeconst int maxd = 20;int s[1<<maxd];int main(){ int D, I, N; scanf("%d", &N); while(N--) { scanf("%d", &D); if(D == -1) break; scanf("%d", &I);原创 2015-01-31 23:06:41 · 508 阅读 · 0 评论 -
UVA1225 Digit Counting
#include int main(){ int n,i,j; scanf("%d", &n); while(n--){ int k,count[10] = {0}; scanf("%d", &k); if(k == 0) count[0] = 1; else for(i=1; i<原创 2015-02-01 09:43:29 · 636 阅读 · 0 评论 -
uva839 not so mobile
#includeusing namespace std;//输入一个子天平,返回天平是否平衡,参数W修改为子天平的总重量bool solve(int& W){ int W1, D1, W2, D2; bool b1 = true, b2 = true; cin >> W1 >> D1 >> W2 >> D2; if(!W1) b1 = solve(W1);原创 2015-01-31 23:27:43 · 487 阅读 · 0 评论 -
uva699 the falling leaves
#include#includeint pile[200], temp;char str[1000];void dfs(int pos){ scanf("%d", &temp); if (temp < 0) return; pile[pos] += temp; dfs(pos-1); dfs(pos+1);}int main(){原创 2015-01-31 23:40:28 · 467 阅读 · 0 评论 -
Periodic Strings UVA455
#include#includeint main(){ char a[100]; int i,j,k=0,l,num; scanf("%d",&num); while(num--) { scanf("%s", a); l = strlen(a); for(j=1; j <= l; j++)原创 2015-02-01 11:55:30 · 437 阅读 · 0 评论 -
uva11988 broken keyboard
#include#includeconst int maxn = 100000 + 5;int last, cur, next[maxn];char s[maxn];int main(){ while(scanf("%s", s+1) == 1) { int n = strlen(s+1); last = cur = 0; nex原创 2015-01-31 21:52:34 · 603 阅读 · 0 评论 -
uva101 the blocks pronlem
对不定长数组的操作:push_back()在尾部添加元素pop_back()在尾部删除元素clear()清空resize()改变大小empty()测试是否为空#include#include#include#includeusing namespace std;const int maxn = 30;int n;vector pile[maxn];//每个pile原创 2015-02-02 10:22:55 · 740 阅读 · 0 评论 -
UVA540 Team Queue(队列简单用法)
队列:queue s定义一个队列push()入队pop()出队front()取队首元素不删除#include#include#includeusing namespace std;const int maxt = 1000 + 10;int main(){ int t, kase = 0; while(scanf("%d", &t) == 1 &&原创 2015-02-02 15:13:23 · 1417 阅读 · 0 评论 -
UVA400 Unix Is
#include#include#includeusing namespace std;const int maxcol = 60;const int maxn = 100 + 5;string filenames[maxn];void print(const string& s,int len, char extra) { cout << s; for(int原创 2015-02-02 17:02:35 · 555 阅读 · 0 评论 -
uva10474 Where is the Marble?
#include#includeusing namespace std;const int maxn = 10000;int main(){ int n, q, x, a[maxn], kase = 0; while(scanf("%d%d", &n, &q) == 2 && n) { printf("CASE# %d:\n", ++kase);//格式原创 2015-02-01 22:46:01 · 447 阅读 · 0 评论 -
201 - Squares
a原创 2014-12-29 08:56:40 · 523 阅读 · 0 评论 -
uva10815 Andy's First Dictionary(集合)
集合:和离散数学上的集合一样,就是只出现一次,里的元素已经从小到大排好了#include#include#include#includeusing namespace std;set dict;int main(){ string s, buf; while(cin >> s) { for(int i= 0; i < s.length(); i++)原创 2015-02-02 11:28:45 · 519 阅读 · 0 评论 -
uva442 Matrix Chain Multiplication
#include#include#include#includeusing namespace std;struct Matrix{ int a,b; Matrix(int a=0, int b=0):a(a),b(b) {}}m[26];//定义了一个结构体变量,并把两个成员都初始化为0stack s;int main(){ int n; ci原创 2015-02-01 20:05:00 · 878 阅读 · 0 评论 -
UVA12096 The SetStack Computer(栈的应用)
这个感觉有点难,集合套在映射里,集合套在不定长数组里,主要是把集合整体理解。#include#include#include#include#include#include#include#include#includeusing namespace std;typedef set Set;//把set 等效成Set,把set 转化成Set类型map IDcache;//定义原创 2015-02-02 14:18:38 · 1200 阅读 · 0 评论 -
UVA1592 Database(Map)
#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;#define ALL(x) x.begin(),x.end()#define INS(X) inserter(x,x.begin())int m,n;原创 2015-02-03 17:54:38 · 686 阅读 · 0 评论 -
UVA136 Ugly Numbers(优先队列应用)
优先队列:“急诊病人插队”priority_queue pq声明优先队列"越小的整数优先级越低的队列"push()入队pop()出队top()取队首元素这个题像了一会,纠结在为什么i == 1500时停,原因就在于这个大循环每次会把最小的那个整数提出来,制造3个新的丑数,然后出队。这样每一循环,按小到大顺序出队一个丑数,直到1500个#include#include原创 2015-02-02 15:43:23 · 590 阅读 · 0 评论 -
UVa102 Ecological Bin Packing(翻译+题解)
Background背景Bin packing, or the placement of objects of certain weights into different bins subject to certain constraints, is an historically interesting problem. Some bin packing problems are原创 2015-02-03 23:26:00 · 829 阅读 · 0 评论 -
UVA1593 - Alignment of Code(这题确实看不太懂)
题中输出时要求“......without trailing and leading spaces......”,否则会wrong answer.1、学会getline的一种用法。2、学会istringstream的用法。3、熟悉c++中的格式输出//#define LOCAL #include #include #include #include #i原创 2015-02-04 00:20:36 · 2815 阅读 · 1 评论 -
UVA227 Puzzle (字符串题)
代码非常清晰,考虑到所有的情况学习这种写法#include#includechar str[10][10], Deal[3000];char ch;int ErrorFlag;int x,y;int Flag;int main(){ Flag=0; while( (gets(str[0])) != NULL && strcmp(str[0],"Z") ){原创 2015-02-03 14:07:37 · 724 阅读 · 0 评论 -
(转载)uva题目难度分级列表
#IDTitleSolved byDifficulty1100The 3n + 1 problem2648512102Ecological Bin Packing106082310071Back to High School Physics95543410055Hashmat t原创 2015-02-03 19:05:43 · 21789 阅读 · 0 评论 -
uva100 3+1
#include#includeusing namespace std;std::map g_Tb1;int CycleLength(int n){ int &cl = g_Tb1[n]; if(cl == 0){ n = (n % 2 == 0) ? (n / 2) : (3 * n + 1); cl = 1 + CycleLength(原创 2015-02-03 19:35:58 · 526 阅读 · 0 评论 -
UVA572 Oil Deposits(DFS求连通块(floodfill 种子填充))
注释后补#include#includeconst int maxn = 100 + 5;char pic[maxn][maxn];int m, n, idx[maxn][maxn];void dfs(int r, int c, int id) { if(r = m || c = n) return ; if(idx[r][c] > 0 || pic[r][c原创 2015-02-06 15:34:13 · 663 阅读 · 0 评论 -
UVA297 Quadtrees(递归!!!)
注释以后补!!!#include#includeconst int len = 32;const int maxn = 1024+10;char s[maxn];int buf[len][len], cnt;void draw(const char* s, int& p, int r, int c, int w) { char ch = s[p++]; if(ch原创 2015-02-06 12:19:43 · 783 阅读 · 0 评论 -
UVA122 trees on the level(BFS)
写了n遍总算是写对了,不能停止地相信自己。#include#include#include#includeusing namespace std;const int maxn = 300;struct Node{ bool have_value;//标记是否赋值 int v;//值 Node *left, *right;//左节点和右节点 Node()原创 2015-02-06 08:49:22 · 430 阅读 · 0 评论 -
UVa548 Tree(递归链表的结合)
#include#include#include#includeusing namespace std;const int maxv = 10000 + 10;int in_order[maxv], post_order[maxv], lch[maxv], rch[maxv];//四个数组,第一个存放中序遍历,第二个存放后序便利,后两个分别存放左节点和右节点的值int n;//n是原创 2015-02-06 12:17:37 · 535 阅读 · 0 评论 -
uva816 Abbott's Revenge
我知知道这题要用BFS,迷宫题,好难啊,我已无奈,苦苦坚持,~~~#include#include#include#include#includeusing namespace std;struct Node{ int r, c; int dir; Node(int rr=0, int cc=0, int ddir=0):r(rr), c(cc), dir(d原创 2015-02-08 17:27:50 · 524 阅读 · 0 评论 -
UVa10129 - Play on Words
c++11CE了c++AC了#include#include#include#include#define MAXN 30using namespace std;int vis[MAXN], N, T, f[MAXN],rank[MAXN], in[MAXN], out[MAXN];void init(){ for(int i = 0; i < MAXN; i++)原创 2015-02-08 18:48:13 · 520 阅读 · 0 评论 -
UVa10305 - Ordering Tasks拓扑排序 天书啊
搜到一个代码 我尼玛 c语言 顿时感到从来没有的亲切写着写着发现什么语言都看不懂啊 泪奔如若有人看到此篇 教导一二 或仅留几句到此一游 我会尤为感激 代码没白抄#include#includeint n, st[110], top, G[110][110], vis[110];void dfs(int u){ int v; vis[u] = 1; for(v原创 2015-02-08 17:49:37 · 804 阅读 · 0 评论 -
Flooded UVA815翻译原题+代码
英语实在是不好,题意都看不懂,背单词又背不下去,那就慢慢翻译吧,反正没事干。翻译不求用词精准,句子也可能不通顺, 只是能理解了题意就好。To enable homebuyers to estimate the cost of flood insurance, a real-estate firm provides clients with the elevation of each 10-原创 2015-01-01 19:25:40 · 2055 阅读 · 1 评论 -
uva712 - S-Trees
好像是个很坑的代码#include#include#include#includeusing namespace std;string str[1200];string value;int main(){ int n,cas=0,k; while(cin >> n && n){ cout << "S-Tree #" << ++cas << ":"原创 2015-02-09 23:41:24 · 498 阅读 · 0 评论 -
uva536 Tree Recovery
感觉算法还是没明白,有种不理解的东西在,最需要的就是去大量的思考,思考简单的,由浅入深。分析:递归。注意树的前序,中序,后序遍历说的是根的访问顺序。 前根序:根,左子树,右子树; 中根序:左子树,根,右子树; 后跟序:左子树,右子树,根。 根据上面的三个式,观察上面三原创 2015-02-09 23:14:21 · 574 阅读 · 0 评论 -
uva673 - Parentheses Balance
题意:括号匹配, 按以下规则:1. 若字符串为空, 则正确.2. 若 A、B 皆正确, 则 AB 也正确.3. 若 A 正确, 则 (A) 与 [A] 都正确.即要求括号与中括号都要匹配.思路:使用栈, 如果当前字符与栈顶字符匹配(必须先进去的是左括号,外面的是右括号才算是匹配的):1. 当前字符为 ')', 栈顶字符为 '('; 2. 当前字符为 ']',原创 2015-02-09 23:52:42 · 551 阅读 · 0 评论 -
uva439 - Knight Moves
题目本身就是象棋里马走“日”,每次共8种走法,记录走过的格子,有限次数内能搜到目标格 ~~思考思考!!! 动脑子 动脑子!!!#include#include#include#include#include#includeusing namespace std;int a[10][10],flag[10][10],count;int step[10][3] = { {1,2原创 2015-02-09 23:34:33 · 1032 阅读 · 0 评论 -
uva127 - "Accordian" Patience
Time limit: 3.000 seconds限时:3.000秒 Problem问题You are to simulate the playing of games of "Accordian" patience, the rules for which are as follows:模拟玩一个“手风琴”纸牌游戏,规则如下:Deal cards on原创 2015-02-10 00:12:36 · 762 阅读 · 0 评论 -
Data Mining UVA1591原题翻译+题解
Dr. Tuple is working on the new data-mining application for Advanced Commercial Merchandise Inc. Tuple先生工作在新的数据挖掘应用对先进的商业货物。(明显句子不通。。。)One of the subroutines for this application works with two arra原创 2015-01-01 21:13:12 · 2107 阅读 · 0 评论 -
uva10562 Undraw the Trees
简简单单 单单纯纯 我就是想坚持下去 到以后发现我竟然是这样入门的 自己是不是都会觉得很奇葩#include#include#includeusing namespace std;const int maxn = 200 + 10;int n;char buf[maxn][maxn];void dfs(int r, int c) { printf("%c(", buf[r原创 2015-02-09 23:05:57 · 498 阅读 · 0 评论 -
UVa10763 - Foreign Exchange
//超时的#include#includeusing namespace std;vector a;vector b;int n,x,y;int main(){ while( cin >> n && n ){ int t = 1; for(int i = 0; i < n; i++){ cin >> x >> y;原创 2015-02-11 22:08:12 · 650 阅读 · 0 评论 -
UVA1592 Database
#include#include#include#include#include#include#includeusing namespace std;mapmaps;int p[10008][6];int main(){ int n,m; lop:while(cin>>n>>m){ string s,t; maps.clear原创 2015-02-23 12:33:25 · 725 阅读 · 0 评论