![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
UVa
杨戬没有你我怎么活
喜欢的人是杨戬!
展开
-
UVA10881 Piotr‘s Ants
#include <iostream>#include <cstdio>#include "bits/stdc++.h"#define ll long longusing namespace std;const int maxn = 10000 + 5;int L,T,n;struct Ant{ int id; int p; // 位移 int d; // L -1 R 1 bool operator < (const Ant原创 2021-12-08 10:33:59 · 631 阅读 · 0 评论 -
UVA-11520 Fill the Square
思路:因为要求是字典序,这道题的第一反应就是从A-Z选取字母,在正方形中从上到下,从左到右这样的顺序去填字母,一旦判断这个字母旁边没有和它一样的,那么就证明这个字母就是正确答案,继续填下一个字母。#include <iostream>#include "bits/stdc++.h"using namespace std;int T,n;vector<vector<char>>grid(10,vector<char>(10));bool safe原创 2021-11-19 10:15:25 · 564 阅读 · 0 评论 -
UVA-11300
#include <iostream>#include "bits/stdc++.h"#define ll long longusing namespace std;int main() { int N; while(scanf("%d",&N) == 1) { vector<ll>a(N+1),c(N,0); ll tmp = 0; for(int i = 1;i<=N;i++)原创 2021-11-19 09:07:35 · 561 阅读 · 0 评论 -
UVa 11729
思路:这道题是一个贪心算法,因为任意两个排在一起的工作,它们的时间相加都是b1+b2+max(j1,j2),所以要把时间最长的放在前面。#include <iostream>#include "bits/stdc++.h"using namespace std;struct Job{ int j,b; bool operator < (const Job & x)const{ return j > x.j; }};i原创 2021-11-18 15:51:38 · 77 阅读 · 0 评论 -
UVA11292
题目:勇者斗恶龙思路:首先排序,然后一个一个去比较。#include <iostream>#include "bits/stdc++.h"using namespace std;int main() { int n,m; while(cin>>n>>m&&(n||m)) { vector<int>d(n),p(m); for(int i = 0;i<n;i++)原创 2021-11-18 15:49:40 · 100 阅读 · 0 评论 -
UVa227
#include <iostream>#include <bits/stdc++.h>#define N 5using namespace std;bool isSafe(int x,int y){ return x>=0 && x<N && y>=0 && y<N;}int...原创 2019-12-15 17:41:40 · 166 阅读 · 0 评论 -
UVa1225
#include <iostream>#include <bits/stdc++.h>using namespace std;int main(){ int n; int num[10] = {0}; while(cin>>n) { while(n--) { in...原创 2019-12-04 08:50:20 · 121 阅读 · 0 评论 -
UVa1586
#include <iostream>#include <bits/stdc++.h>using namespace std;int main(){ int n; double num[4] = {12.01,1.008,16,14.01}; string s; while(cin>>n) { ...原创 2019-12-04 08:35:18 · 128 阅读 · 0 评论 -
UVA1585
#include <iostream>#include <bits/stdc++.h>using namespace std;int main(){ int n; string s; while(cin>>n) { for(int i = 0;i<n;i++) { ...原创 2019-12-03 22:20:34 · 161 阅读 · 0 评论 -
Audiophobia UVA - 10048
这道题很像CCF的青蛙跳跳#include <iostream>#include <bits/stdc++.h>#define maxn 101#define INF 0x3f3f3f3fusing namespace std;struct Edge{ int u,v,w; Edge(int i,int j,int k):u(i),v(j)...原创 2019-03-15 20:39:03 · 122 阅读 · 0 评论 -
Calling Circles UVA - 247
这道题超级妙!#include <iostream>#include <bits/stdc++.h>#define maxn 30using namespace std;struct Edge{ int u,v; Edge(int i,int j):u(i),v(j) {} Edge() {}};int n,m;int p[m...原创 2019-03-15 19:51:53 · 129 阅读 · 2 评论 -
Common Subexpression Elimination UVA - 12219
#include <iostream>#include <bits/stdc++.h>#define maxn 50005using namespace std;string s;int k,u;//u是单词的idstruct tree{ string tmp; int lch,rch; bool operator < (co...原创 2019-03-10 22:59:06 · 72 阅读 · 0 评论 -
Maximum Product UVA - 11059
#include <iostream>#include <bits/stdc++.h>#define maxn 20#define ll long longusing namespace std;ll num[maxn];int main(){ int n; int kase = 0; ll ans; ll temp; ...原创 2019-03-07 14:53:53 · 129 阅读 · 0 评论 -
Buy or Build POJ - 2784
其实这道题我没有写对~我一开始写的是UVa 1151,结果是错的,然后看到有个博主说POJ上有道一毛一样的题目,迅速水过,但是到了UVa就各种WA,心里好奇,一提交POJ竟然AC。。。好吧(╯▽╰),先贴,等我找找原因为什么错再来改改。#include <iostream>#include <algorithm>#include <vector>...原创 2019-03-14 19:44:49 · 198 阅读 · 0 评论 -
Fill UVA - 10603
#include <iostream>#include <bits/stdc++.h>#define maxn 210using namespace std;int a,b,c,d;struct Node{ int v[3],dist; bool operator < (const Node& rhs) const {...原创 2019-03-10 09:52:16 · 98 阅读 · 0 评论 -
Division UVA - 725
#include <iostream>#include <bits/stdc++.h>#define maxn 10using namespace std;int num[maxn];bool check(int a,int b){ memset(num,0,sizeof(num)); if(b>98765) return false;...原创 2019-03-07 09:22:34 · 162 阅读 · 0 评论 -
Patrol Robot UVA - 1600
#include <iostream>#include <bits/stdc++.h>#define maxn 21using namespace std;struct Node{ int r,c,k; Node(int a,int b,int d):r(a),c(b),k(d) {} Node() {}};int maze[max...原创 2019-03-07 08:43:33 · 131 阅读 · 0 评论 -
Bandwidth UVA - 140
#include <iostream>#include <bits/stdc++.h>#define maxn 27#define inf 0x3f3f3f3fusing namespace std;char letter[maxn];int p[maxn];int pos[maxn];int f[maxn];int main(){ str...原创 2019-03-09 11:21:05 · 109 阅读 · 0 评论 -
Krypton Factor UVA - 129
#include <iostream>#include <bits/stdc++.h>#define maxn 100using namespace std;int n,L;int s[maxn];int cnt;int ans;int dfs(int cur){ if(cnt++ == n) { int j = 0;...原创 2019-03-09 08:51:01 · 101 阅读 · 0 评论 -
It's not a Bug, it's a Feature!
这道题的关键是二进制的或与运算~现在特别感激计算机基础的老师给了我们做bomb实验,受益匪浅。#include <iostream>#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxm 105#define maxn ((1<<20)+1)using namespace std;...原创 2019-03-16 11:09:06 · 986 阅读 · 0 评论 -
Slim Span UVA - 1395
#include <iostream>#include <bits/stdc++.h>#define inf 10000000#define maxn 110#define maxm 110*50using namespace std;struct Node{ int u,v,w; bool operator < (const Node...原创 2019-03-12 09:21:05 · 205 阅读 · 0 评论 -
Page Hopping UVA - 821
水题来一发.#include <iostream>#include <bits/stdc++.h>#define maxn 105#define INF 0x3f3f3f3fusing namespace std;int d[maxn][maxn];int n;void init(){ memset(d,INF, sizeof(d)); ...原创 2019-03-16 14:56:28 · 114 阅读 · 0 评论 -
Database(UVa 1592)
#include <iostream>#include <bits/stdc++.h>#define maxn 100001using namespace std;map<string,int>IDcache;vector<string>data;map<pair<int,int>,int>mp;int a[m...原创 2019-02-09 12:14:48 · 84 阅读 · 0 评论 -
UVA12563
这道题是普通的0-1背包问题,但是需要注意的是我们要求最多曲目下最长的歌的时间。所以当曲目数相同时,要取最长的时间。#include <iostream>#include <bits/stdc++.h>#define maxn 100000#define INF 0x3f3f3f3fusing namespace std;int w[60];i...原创 2019-05-17 09:06:02 · 230 阅读 · 0 评论 -
Charm Bracelet POJ - 3624
这种题目一开始是用二维数组写的,但是会超时。后面用一维数组是因为恰巧信息的流动都是至右向左,所以可以覆盖掉d[j].但是如果换个思维,视j为背包的空余,那么方向就相反了,就不能用一位数组了。#include <iostream>#include <bits/stdc++.h>#define maxn 3450#define INF 0x3f3f3f3fu...原创 2019-05-16 09:50:54 · 84 阅读 · 0 评论 -
Unidirectional TSP UVA - 116
这道题也成功AC~#include <iostream>#include <bits/stdc++.h>#define maxn 100+10#define INF 0x3f3f3f3fusing namespace std;int maze[maxn][maxn];int d[maxn][maxn];int row[3];int m,n;int ...原创 2019-05-15 20:40:23 · 62 阅读 · 0 评论 -
The Tower of Babylon UVA - 437
这也是一道DP。但是需要注意的是题目没有告诉我们高度和宽度的限制,所以矩阵会很稀疏,我们可以改用立方体的下标和长宽高的序号来表示。#include <iostream>#include <bits/stdc++.h>#define maxn 30+10using namespace std;int l[maxn][3];//长度int d[maxn][3...原创 2019-05-15 14:09:20 · 72 阅读 · 0 评论 -
UVA1025
这是一道DP题。感觉稍微有一点感悟,dp就像是一棵树的底层树叶,我们要做的就是往上开始堆。这道题有两个变量,一个是时间,一个是位置。边界就是t = T,s(站台) = n时,d[t][s] = 0;表示的是你需要在站台等待的时间,仅指你不在地铁上的时间。所以有三种状态:一种是你上一秒在站台上等,现在再等一秒钟;第二种是左边有车过来,所以等待的时间就是到下一个站台的等待时间(车上的时间不算)...原创 2019-05-15 13:41:00 · 338 阅读 · 0 评论 -
Unique Snowflakes UVA - 11572
#include <iostream>#include <bits/stdc++.h>using namespace std;vector<int>a;set<int>S;int main(){ int T,n; int num; cin>>T; while(T--) { ...原创 2019-05-05 21:17:48 · 131 阅读 · 0 评论 -
Wine trading in Gergovia UVA - 11054
#include <iostream>#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+10;int main(){ int n; int a[maxn]; while(cin>>n && n) { lon...原创 2019-05-05 16:28:51 · 134 阅读 · 0 评论 -
Fabled Rooks UVA - 11134
#include <iostream>#include <bits/stdc++.h>#define maxn 5000+10using namespace std;bool solve(int * a,int * b,int n,int * c){ fill(c+1,c+n+1,-1); for(int i = 1;i<=n;i++)...原创 2019-05-05 16:10:39 · 80 阅读 · 0 评论 -
Building for UN UVA - 1605
这道题真是神了。我真是没有想到可以这么写。#include <iostream>#include <bits/stdc++.h>using namespace std;int main(){ int n; int H = 2; char t; while(cin>>n) { cout<...原创 2019-05-04 22:58:47 · 92 阅读 · 0 评论 -
UVA(120)
#include <iostream>#include <bits/stdc++.h>using namespace std;vector<int>a;int main(){ string s; int num; while(getline(cin,s)) { cout<<s<<...原创 2019-05-04 22:27:55 · 359 阅读 · 0 评论 -
Play on Words UVA - 10129
#include <iostream>#include <bits/stdc++.h>#define maxn 27using namespace std;int n;bool visited[maxn];int G[maxn][maxn];int in[maxn],out[maxn];void dfs(int u){ visited[u] =...原创 2019-03-04 08:49:39 · 87 阅读 · 0 评论 -
Knight Moves UVA - 439
其实就是bfs。#include <iostream>#include <bits/stdc++.h>#define maxn 9using namespace std;struct Node{ int r,c; Node(int i,int j):r(i),c(j){} Node(){}};int maze[maxn][maxn...原创 2019-03-06 17:57:04 · 134 阅读 · 0 评论 -
S-Trees UVA - 712
#include <iostream>#include <bits/stdc++.h>#define maxn 100using namespace std;int n,m;int v[maxn];string leave,q;void solve(string s){ int layer = 1; for(int i = 0;i<...原创 2019-03-06 16:00:44 · 72 阅读 · 0 评论 -
Quadtrees UVA - 297
#include <iostream>#include <bits/stdc++.h>#define len 32#define maxn 1024+10using namespace std;bool buf[len][len];int cnt;//计数/**2 13 4**/void draw(string s,int& p,i...原创 2019-02-23 17:09:26 · 103 阅读 · 0 评论 -
The Falling Leaves UVA - 699
#include <iostream>#include <bits/stdc++.h>#define maxn 10000using namespace std;int order[maxn],n;int rsum[maxn],lsum[maxn];int Lmax,Rmax;//a是坐标,num是编号void build(int a){ i...原创 2019-02-23 16:19:22 · 60 阅读 · 0 评论 -
Not so Mobile UVA - 839
#include <iostream>#include <bits/stdc++.h>using namespace std;int solve(int &w){ int w1,w2,d1,d2; bool b1 = true,b2 = true; cin>>w1>>d1>>w2>>...原创 2019-02-23 11:40:24 · 75 阅读 · 0 评论 -
Tree UVA - 548
#include <iostream>#include <bits/stdc++.h>#define maxn 10000+10using namespace std;int in_order[maxn],post_order[maxn],lch[maxn],rch[maxn];int n;bool read_line(int* a){ strin...原创 2019-02-23 10:58:13 · 86 阅读 · 0 评论