算法竞赛入门经典(训练指南)----算法设计基础
wang2147483647
这个作者很懒,什么都没留下…
展开
-
UVA 11078(p41)----Open Credit System
#includeusing namespace std;const int INF=99999999;int n;int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); int ans=-INF,maxi=-INF; for(int i=原创 2016-03-01 11:44:30 · 247 阅读 · 0 评论 -
UVA 11292(p1)----The Dragon of Loowater
#includeusing namespace std;const int maxn=20000+50;int n,m,ans,now;int hero[maxn];int dragon[maxn];int main(){ while(scanf("%d%d",&n,&m)==2&&n) { ans=0; now=0;原创 2016-02-28 19:34:09 · 219 阅读 · 0 评论 -
UVA 11300(p4)----Spreading the Wealth
#includeusing namespace std;typedef long long LL;const int maxn=1e6+50;int n;LL tot;LL c[maxn],a[maxn];int main(){ while(scanf("%d",&n)!=EOF) { tot=0; for(int i=0; i<n;原创 2016-02-28 19:35:35 · 192 阅读 · 0 评论 -
UVA 11384(p25)----Help is needed for Dexter
#includeusing namespace std;int n;int solve(int n){ return n==1?1:solve(n/2)+1;}int main(){ while(scanf("%d",&n)!=EOF) { printf("%d\n",solve(n)); } return 0;}原创 2016-02-28 19:37:44 · 269 阅读 · 0 评论 -
UVA 11464(p15)----Even Parity
#include#define debuusing namespace std;const int maxn=20;const int INF=999999;int b[maxn][maxn];int n,a[maxn][maxn];int solve(int s){ int num=0; memset(b,0,sizeof(b)); for(int i=0原创 2016-02-28 19:40:34 · 243 阅读 · 0 评论 -
UVA 11729(p2)----Commando War
#includeusing namespace std;const int maxn=1010;struct point{ int b,j;};int n,cas=0;point a[maxn];int cmp(point x,point y){ if(x.j==y.j) return x.b<y.b; else return x.j>y.j;}int原创 2016-02-28 19:42:04 · 207 阅读 · 0 评论 -
LA 3708(p7)----Graveyard
#includeusing namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { double x,ans=0.0; for(int i=1;i<n;i++) { x=(double)i/n*(n+m);原创 2016-02-28 19:47:17 · 302 阅读 · 0 评论 -
LA 3635(p30)----Pie
#include#define debuusing namespace std;const double eps=1e-7;const double pi=acos(-1.0);const int maxn=1e4+50;int n,f;double maxarea,a[maxn];int check(double area){ int num=0; for(in原创 2016-02-29 21:48:45 · 295 阅读 · 0 评论 -
UVA11520(p31)----Fill the Square
#include#define debuusing namespace std;const int maxn=15;int cas=0,n;char g[maxn][maxn];void input(){ printf("Case %d:\n",++cas); scanf("%d\n",&n); for(int i=0; i<n; i++) {原创 2016-02-29 22:17:22 · 273 阅读 · 0 评论 -
UVA 11462(p39)----Age Sort
#includeusing namespace std;int n,a[110];int main(){ while(scanf("%d",&n)==1&&n) { memset(a,0,sizeof(a)); for(int i=0; i<n; i++) { int x; sc原创 2016-03-01 10:51:19 · 236 阅读 · 0 评论 -
UVA 11627(p80)----Slalom
#include#define debuusing namespace std;const int maxn=1e6+50;int maxx,w,vh,n,s,ans,tmp;int x[maxn],y[maxn],ski[maxn];int check(int speed){ double l=(double)x[0],r=(double)(x[0]+w); for原创 2016-03-26 20:10:41 · 575 阅读 · 0 评论 -
UVA 10881(p9)----Piotr's Ants
#includeusing namespace std;const int maxn=1e4+50;struct point{ int id,p,d;};int pos[maxn];point a[maxn],b[maxn];int cmp(point a,point b){ return a.p<b.p;}int main(){ int l,t,n原创 2016-02-28 19:30:51 · 262 阅读 · 0 评论 -
UVA 11039(p78)----Building designing
#include#define debuusing namespace std;const int maxn=5*1e5+50;int a[maxn];int b[maxn];int n,num1,num2;void solve(){ int ans=0,pos,flag,now; sort(a,a+num1); sort(b,b+num2); if原创 2016-03-23 22:21:16 · 378 阅读 · 0 评论 -
UVA 10970(p79)----Big Chocolate
#includeusing namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { printf("%d\n",n*m-1); } return 0;}题目地址:https://uva.onlinejudge.org/index.php?optio原创 2016-03-23 22:17:53 · 220 阅读 · 0 评论 -
UVA 11549(p42)----Calculator Conundrum
#includeusing namespace std;typedef long long LL;int a[15];int n,k,t;set s;int cal(int k){ int len=0,ans=0; LL kk=(long long)k*k; while(kk>0) { a[len++]=kk%10;原创 2016-03-01 16:22:27 · 374 阅读 · 0 评论 -
LA 2678(p48)----Subsequence
#include#define debuusing namespace std;const int INF=9999999;const int maxn=1e5+50;int n,s;int a[maxn],sum[maxn];void solve(){ int ans=INF; for(int j=0; j<n; j++) { int i=原创 2016-03-01 17:19:30 · 245 阅读 · 0 评论 -
LA 3905(p45)----Meteor
#include#define debuusing namespace std;typedef double DB;struct point{ int flag; DB w; point(DB a=0.0,int b=0):w(a),flag(b) {}};int n;DB w,h;vector all;void make(DB px,DB py,DB原创 2016-03-05 21:51:00 · 360 阅读 · 0 评论 -
UVA 11636(p78)----Hello World!
#includeusing namespace std;int main(){ int n,cas=0; while(scanf("%d",&n)!=EOF) { if(n<0) break; int step=0,now=1; for(int i=1;i<=20;i++) { i原创 2016-03-06 17:41:38 · 304 阅读 · 0 评论 -
UVA 10125(p89)----Sumsets
#include#define debuusing namespace std;typedef long long LL;const int maxn=1e3+50;const LL INF=1e10;int n;set s;LL a[maxn];map > num;int check(LL x,LL y){ LL tmp=x-y; /*if(s.count(原创 2016-03-10 21:45:28 · 344 阅读 · 0 评论 -
UVA 10905(p79)----Children's Game
#include#define debuusing namespace std;int n;string st[55];int cmp(string st1,string st2){ return st1+st2>st2+st1;}int main(){#ifdef debug freopen("in.in","r",stdin);#endif // debg原创 2016-03-10 21:52:33 · 337 阅读 · 0 评论 -
LA 4254(p80)----Processor
#include#define debuusing namespace std;const int INF=1e7;const int maxn=1e4+50;struct point{ int l,r,w; bool operator < (const point& rhs) const { return r>rhs.r; }};i原创 2016-03-23 21:42:48 · 328 阅读 · 0 评论 -
LA 3695(p52)----Distant Galaxy
#include#define debuusing namespace std;const int maxn=100+50;struct point{ int x,y; bool operator < (const point& rhs) const { if(rhs.y==y) return rhs.x>x; else retur原创 2016-03-23 21:51:23 · 303 阅读 · 0 评论 -
LA 3029(p50)----City Game
#include#define debuusing namespace std;const int maxn=1e3+50;int n,m;int g[maxn][maxn];int up[maxn][maxn];int lt[maxn][maxn];int rt[maxn][maxn];void init(){ memset(g,0,sizeof(g)); m原创 2016-03-23 22:00:41 · 675 阅读 · 0 评论 -
UVA 10382(p79)----Watering Grass
#include#define debuusing namespace std;const int maxn=1e4+50;struct point{ double l,r; bool operator < (const point& rhs) const { if(rhs.l==l) return rhs.r>r; else re原创 2016-03-23 22:13:38 · 300 阅读 · 0 评论 -
UVA 11100(p81)----The Trip, 2007
#include#define debuusing namespace std;const int maxn=1e4+50;int ans,n;int a[maxn];map m;void solve(){ sort(a,a+n); printf("%d\n",ans); for(int i=0; i<ans; i++) { prin原创 2016-03-26 20:24:40 · 624 阅读 · 0 评论