算法竞赛入门经典(第二版)----高效算法设计
文章平均质量分 58
wang2147483647
这个作者很懒,什么都没留下…
展开
-
UVA 1149(p253)----Bin Packing
#include#include#include#includeusing namespace std;int a[100050],ans,t,cas,n,l,r,w;int main(){ // freopen("in.in","r",stdin); scanf("%d",&t); int cas=0; while(t--) {原创 2016-02-25 23:32:22 · 278 阅读 · 0 评论 -
UVA 1619(p256)----Feel Good
#includeusing namespace std;typedef long long LL;const int maxn=1e5+50;int n;LL a[maxn];LL sum[maxn];int l[maxn],r[maxn];int main(){ int cas=0; while(scanf("%d",&n)!=EOF) {原创 2016-02-26 13:45:08 · 334 阅读 · 0 评论 -
UVA 1623(p256)----Enter the Dragon
#include#include#include#includeusing namespace std;const int maxn=1e6+50;int lake,n;int a[maxn];int ans[maxn];int have[maxn];set s;int main(){ int t; scanf("%d",&t); while(t--原创 2016-02-26 13:45:54 · 337 阅读 · 0 评论 -
UVA 11054(p237)----Wine trading in Gergovia
#include#include#includeusing namespace std;int main(){ int n; ios::sync_with_stdio(false); while((cin>>n)&&n) { long long next=0,ans=0,x; for(int i=0;i<n;i++)原创 2016-02-27 13:28:25 · 207 阅读 · 0 评论 -
UVA 11093(p246)----Just Finish it up
#include#include#include#include#define debuusing namespace std;const int maxn=1e5+50;int cas=0,n;int v[maxn];int gt[maxn];int cost[maxn];void solve(){ memset(v,0,sizeof(v)); int i原创 2016-02-27 13:30:26 · 541 阅读 · 0 评论 -
UVA 11491(p253)----Erasing and Wining
#include#include#includeusing namespace std;const int maxn=1e5+50;int n,d,tail,cnt;char st[maxn];int main(){ while(scanf("%d%d",&n,&d)==2&&n) { char ans[maxn]; tail=0;原创 2016-02-27 13:39:17 · 231 阅读 · 0 评论 -
UVA 11536(p255)----Smallest Sub-Array
#include#include#include#include#includeusing namespace std;const int INF=1e7;const int maxn=1e6+50;int x[maxn];int v[maxn];queue q;int cas=0,n,m,k;void prepare(){ x[1]=1; x[2]=2;原创 2016-02-27 13:41:56 · 234 阅读 · 0 评论 -
UVA 11572(p239)----Unique snowflakes
#include#include#include#includeusing namespace std;int maxx,top,pos[1000010],a[1000010],t,n;int main(){ scanf("%d",&t); while(t--) { scanf("%d",&n); memset(a,0,size原创 2016-02-27 13:45:48 · 261 阅读 · 0 评论 -
UVA 11925(p254)----Generating Permutations
#include#include#include#include#include#includeusing namespace std;vector ans;deque q;int n;int check(){ for(int i=1;i<q.size();i++) if(q[i]<q[i-1]) return 0; return 1;}i原创 2016-02-27 13:51:33 · 236 阅读 · 0 评论 -
UVA 12545(p253)----Bits Equalizer
#include#include#includeusing namespace std;int t,l,zero,one,temp1,temp2,qnum;string st1,st2;int main(){ ios::sync_with_stdio(false); cin>>t; int cas=0; while(t--) {原创 2016-02-27 14:05:08 · 298 阅读 · 0 评论 -
UVA 120(p236)----Stacks of Flapjacks
#include#include#include#includeusing namespace std;string st;int a[1000],num;void rev(int pos){ cout<<num+1-pos<<" "; for(int i=0; i<=pos/2; i++) { int temp=a[i];原创 2016-02-25 22:27:06 · 490 阅读 · 0 评论 -
UVA 1614(p254)----Hell on the Markets
#include#include#include#includeusing namespace std;const int maxn=100000+50;struct point{ int v,pos,ans;};int n;point a[maxn];int cmp(point a,point b){ return a.v<b.v;}int main(原创 2016-02-26 13:44:23 · 276 阅读 · 0 评论 -
UVA 1612(p254)----Guess
#include#define debuusing namespace std;const int maxn=1e6;struct point{ double v[3];} a[maxn];int n,cas=0;int rk[maxn];double ans[maxn];vector g[maxn];void solve(int s,int k){ dou原创 2016-02-26 13:43:21 · 285 阅读 · 0 评论 -
UVA 1152(p237)----4 Values Whose Sum is Zero
#include#include#includeusing namespace std;long long ans,sum[16000000];int cas,a[5000],b[5000],c[5000],d[5000],n;int main(){ scanf("%d",&cas); while(cas--) { scanf("%d",&n)原创 2016-02-25 23:34:02 · 228 阅读 · 0 评论 -
UVA 1312(p256)----Cricket Field
#include#include#include#includeusing namespace std;const int maxn=1200;int n,w,h;int row,col;int d[maxn];int arr[maxn][2];int x[maxn],y[maxn];int idx[10000+50],idy[10000+50];int mat[maxn]原创 2016-02-25 23:56:58 · 244 阅读 · 0 评论 -
UVA 1471(p242)----Defense Lines
#include#define debuusing namespace std;const int maxn=2*1e5+50;const int INF=1e9+50;struct point{ int w,g; point(int a=0,int b=0):w(a),g(b) {} bool operator < (const point& rhs) con原创 2016-03-10 21:19:09 · 457 阅读 · 0 评论 -
UVA 11134(p237)----Fabled Rooks
#include#define debuusing namespace std;const int maxn=5*1e3+50;struct point{ int l,r,id;};int n,v[maxn];point a[maxn],b[maxn];int ansx[maxn],ansy[maxn];int cmp(point a,point b){ i原创 2016-03-10 21:30:13 · 277 阅读 · 0 评论 -
UVA 1442(p249)----Cave
#include#includeusing namespace std;const int maxn=1000000+50;int p[maxn],s[maxn],water[maxn];int t,n;int main(){ ios::sync_with_stdio(false); cin>>t; while(t--) { cin>>n;原创 2016-02-26 13:27:45 · 271 阅读 · 0 评论 -
UVA 1605(p236)----Building for UN
#includeusing namespace std;char ans[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};int main(){ int cas=0,n; while(scanf("%d",&n)!=EOF) { cas++; if(cas!=1)原创 2016-02-26 13:39:39 · 245 阅读 · 0 评论 -
UVA 1606(p238)----Amphiphilic Carbon Molecules
#include#include#include#includeusing namespace std;const int maxn=2000;struct point{ int x,y; double rad;};point g[maxn];int x[maxn],y[maxn],r[maxn],n;int check(point a,point b){原创 2016-02-26 13:40:39 · 306 阅读 · 0 评论 -
UVA 1610(p253)----Party Games
#include#include#includeusing namespace std;const int maxn=1000+50;int n;string st[maxn];string st1,st2;void solve(){ string ans="",st3=""; sort(st,st+n); st1=st[n/2-1];st2=st[n/2原创 2016-02-26 13:42:34 · 312 阅读 · 0 评论 -
UVA 714(p244)----Copying Books
#include#include#include#include#define debuusing namespace std;const int maxn=1e7+50;typedef long long LL;int v[maxn];LL sum,maxx;LL n,m,a[maxn],l,r,mid;int check(LL limit){ int i=0,n原创 2016-02-25 23:17:58 · 197 阅读 · 0 评论