2014 Asia Beijing Regional Contest
来源:互联网 发布:js获取span的value 编辑:程序博客网 时间:2024/04/29 17:38
A. HDU 5112
// whn6325689#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#include <functional>#include <numeric>using namespace std;typedef long long ll;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define eps 1e-9#define INF 0x3f3f3f3f#define LLINF 1LL<<62template<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------struct Node{double a,b;}t[10010];bool cmp(Node a,Node b){return a.a<b.a;}int main(){int T,n,m,cas=0;read(T);while(T--){read(n);for(int i=0;i<n;i++)scanf("%lf %lf",&t[i].a,&t[i].b);sort(t,t+n,cmp);double ans=-INF;for(int i=1;i<n;i++){double tt=t[i].a-t[i-1].a;double dis=abs(t[i].b-t[i-1].b);double v=dis/tt;if(v>ans)ans=v ;}printf("Case #%d: %.2f\n",++cas,ans); }return 0;}
B. HDU 5113
暴力染色
多用几种染色的方法,然后check一下
多种之后不行就是不行咯
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define maxn 10#define maxk 100using namespace std;int t,n,m,k;int a[maxn][maxn];struct C{ int id; int num; bool operator <(const C &x) const { return num<x.num; }}c[maxk];bool check(){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j] == a[i][j-1] || a[i][j] == a[i][j+1] || a[i][j] == a[i-1][j] || a[i][j] == a[i+1][j]) return false; return true;}void print(){ printf("YES\n"); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) printf("%d%c",a[i][j],j==m?'\n':' ');}void solve1(){ memset(a,0,sizeof(a)); int Index = 1; C temp; temp = c[Index];int num=0;int b[maxn][maxn]; for(int i=1;i<=n;i++) for(int j=i%2==0?2:1;j<=m;j+=2) { if(temp.num == 0) {Index++;temp = c[Index];} b[i][j] = num++; a[i][j] = c[Index].id; temp.num--; } for(int i=1;i<=n;i++) for(int j=(i+1)%2==0?2:1;j<=m;j+=2) { if(temp.num == 0) {Index++;temp = c[Index];} b[i][j] = num++; a[i][j] = c[Index].id; temp.num--; } for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cout<<b[i][j]<<" ";cout<<endl;}}void solve2(){ memset(a,0,sizeof(a)); int Index = 1; C temp; temp = c[Index]; for(int i=2;i<=m+n;i+=2) for(int j=1;j<i;j++) if(i-j>=1 && i-j<=n && j<=m) { if(temp.num == 0) {Index++;temp = c[Index];} a[i-j][j] = c[Index].id; temp.num--; } for(int i=3;i<=m+n;i+=2) for(int j=1;j<i;j++) if(i-j>=1 && i-j<=n && j<=m) { if(temp.num == 0) {Index++;temp = c[Index];} a[i-j][j] = c[Index].id; temp.num--; }}void solve3(){ memset(a,0,sizeof(a)); int Index = 1; C temp; temp = c[Index]; for(int i=3;i<=m+n;i+=2) for(int j=1;j<i;j++) if(i-j>=1 && i-j<=n && j>=1 && j<=m) { if(temp.num == 0) {Index++;temp = c[Index];} a[i-j][j] = c[Index].id; temp.num--; } for(int i=2;i<=m+n;i+=2) for(int j=1;j<i;j++) if(i-j>=1 && i-j<=n && j>=1 && j<=m) { if(temp.num == 0) {Index++;temp = c[Index];} a[i-j][j] = c[Index].id; temp.num--; }}int main(){ scanf("%d",&t); for(int cas = 1;cas <=t;cas++) { scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++) { scanf("%d",&c[i].num); c[i].id = i; }printf("Case #%d:\n",cas); sort(c+1,c+1+k); reverse(c+1,c+1+k); solve1(); if(check()) {print();continue;} solve2(); if(check()) {print();continue;} solve3(); if(check()) {print();continue;} printf("NO\n"); }}
D. HDU 5114
简单的区间DP,廖神
//By LH#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;typedef long long LL;int n, a[205], b[205];LL f[205][205];LL dp(int x, int y){ int i; LL tmp, now; if (f[x][y] != -1) return f[x][y]; if (x+1 == y) return 0; tmp = 1000000000; for (i = x+1; i < y; i++) { now = dp(x, i) + dp(i, y) + a[i]+b[x]+b[y]; tmp = min(now, tmp); } f[x][y] = tmp; return f[x][y];}int main(){ int i, T, cnt; scanf("%d", &T); cnt = 0; while (T--) { cnt++; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); a[0] = 0; a[n+1] = 0; for (i = 1; i <= n; i++) scanf("%d", &b[i]); b[0] = 0; b[n+1] = 0; memset(f, -1, sizeof(f)); printf("Case #%d: %I64d\n", cnt, dp(0, n+1)); } return 0;}
H. HDU 5119
简单的背包DP
如果数量级再大一些用异或方程组,见前几篇博客
//By LH#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;typedef long long LL;LL dp[2][1 << 22]; int num[44]; int main() { int t, n, m, icase = 1; LL ans; scanf("%d", &t); while (t--) { memset (dp, 0, sizeof(dp)); scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); dp[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j <= (1 << 20); j++) dp[i % 2][j] = dp[1 - (i % 2)][j] + dp[1 - (i % 2)][j ^ num[i]]; ans = 0; for (int i = m; i <= (1 << 20); i++) ans += dp[n % 2][i]; printf("Case #%d: %I64d\n", icase++, ans); } return 0; }
I. HDU 5120
简单的计算几何
大圆面积并 - 两个大圆小圆面积并 + 两个小圆并
A神代码
#include <cstdio>#include <iostream>#include <cmath>#include <cstring>#include <vector>#include <algorithm>#define eps 1e-8#define maxn 1010#define PI (acos(-1))using namespace std;int dlcmp(double x){ return x<-eps?-1:x>eps;}double sqr(double x){ return x*x;}struct Point{ double x,y; Point(){}; Point(double xx,double yy):x(xx),y(yy){}; Point operator - (const Point &a) const {return Point(x-a.x,y-a.y);} Point operator + (const Point &a) const {return Point(x+a.x,y+a.y);} //double operator * (const Point &a) const {return x*a.x+y*a.y;} Point trunc(double d) { double dis(Point,Point); double len = dis(*this,Point(0,0)); return Point(x*d/len,y*d/len); } Point rotate(double a) { return Point( x*cos(a)-y*sin(a),y*cos(a)+x*sin(a) ); }};double dot(Point a,Point b){ return a.x*b.x+a.y*b.y;}struct Segment{ Point s,e; Segment(){} Segment(Point ss,Point ee):s(ss),e(ee){}};struct Rectangle{ Point lt; Point rb;};struct Circle{ Point o; double r; Circle(){} Circle(Point a,double l):o(a),r(l){} double area(){return sqr(r)*PI;}};double cross(double x1,double y1,double x2,double y2){ return x1*y2-x2*y1;}double cross(Point a,Point b){ return a.x*b.y-b.x*a.y;}double cross(Point a,Point b,Point s){ double x1=a.x-s.x,y1=a.y-s.y; double x2=b.x-s.x,y2=b.y-s.y; return x1*y2-x2*y1;}double dis(Point a,Point b){ return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) );}int inter_circle(Circle c1,Circle c2,Point &p1,Point &p2){ double len=dis(c1.o,c2.o); if( dlcmp(len - c1.r - c2.r)>0 ) return 0; double s = ( sqr(c1.r)-sqr(c2.r)+sqr(len) )/len/2; double h = sqrt( sqr(c1.r) - sqr(s) ); Point vec=c2.o-c1.o; Point p0 = c1.o+vec.trunc(s); p1 = p0+vec.rotate(PI/2).trunc(h); p2 = p0-vec.rotate(PI/2).trunc(h); return 1;}double vec_angle(Point a,Point b){ double tmp=dot(a,b)/(dis( a,Point(0,0) )*dis( b,Point(0,0) )); if(dlcmp(tmp-1)>=0) tmp = 1; if(dlcmp(tmp+1)<=0) tmp = -1; return acos(tmp);}double arc_area(Point a,Point b,Circle c){ double theta = vec_angle(a-c.o,b-c.o); double sf = sqr(c.r)*theta/2.0; double st = sqr(c.r)*sin(theta)/2.0; if(dlcmp(cross(a,b,c.o))>0) return sf-st; else return c.area()-sf+st;}double circle_and(Circle a,Circle b){ if( dlcmp(dis(a.o,b.o) - a.r - b.r) >=0 ) return 0; if(a.r>b.r) swap(a,b); if(dlcmp(b.r - dis(a.o,b.o) - a.r)>=0) return a.area(); Point p1,p2; inter_circle(a,b,p1,p2); return abs( arc_area(p2,p1,a) + arc_area(p1,p2,b) );}int t,cas;double R,r;int main(){ scanf("%d",&t); for(int cas = 1;cas <= t;cas++) { Circle a1,a2,b1,b2; scanf("%lf%lf",&r,&R); scanf("%lf%lf",&a1.o.x,&a1.o.y); scanf("%lf%lf",&b1.o.x,&b1.o.y); a2.o = a1.o; b2.o = b1.o; a1.r = r; a2.r = R; b1.r = r; b2.r = R; //cout<<circle_and(a2,b2)<<endl; double ans = circle_and(a2,b2) - circle_and(a2,b1) - ( circle_and(a1,b2) - circle_and(a1,b1) ); printf("Case #%d: %.6lf\n",cas,ans); } return 0;}
K. HDU 5126
很简单的题目,但是一定要思考清楚
// whn6325689#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#include <functional>#include <numeric>using namespace std;typedef long long ll;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define eps 1e-9#define INF 0x3f3f3f3f#define LLINF 1LL<<62template<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------int a[1000010]; int main() { int T,n,i,j; int min,cnt,cas=1; read(T); while(T--) { cnt=0; read(n); for(i=0;i<n;i++) read(a[i]); min=INF;for(int i=n-1;i>=0;i--)if(a[i]<min)min=a[i];elsecnt++; printf("Case #%d: %d\n",cas++,cnt); } return 0; }
0 0
- 2014 Asia Beijing Regional Contest
- UVALive 7061 Dire Wolf (dp)(The 2014 ACM-ICPC Asia Beijing Regional Contest D)
- 2011 Asia Beijing Regional Online Contest-1005 hdu4044 GeoDefense
- 2011 Asia Beijing Regional Online Contest-1007 hdu4046 Panda
- 2011 Asia Beijing Regional Online Contest-1002 hdu4041 Eliminate Witches!
- 2011 Asia Beijing Regional Online Contest-1010 hdu4049 Tourism Planning
- 2011 Asia Beijing Regional Online Contest-1006 hdu4045 Machine scheduling
- 2011 Asia Beijing Regional Online Contest-1004 hdu4043 FXTZ II
- 2011 Asia Beijing Regional Online Contest-1005 hdu4044 GeoDefense-tjuqxy
- 2015 Asia BeiJing Regional Contest A. Xiongnu's Land(二分)
- HihoCoder 1249(2015 Asia Beijing Regional Contest)
- HihoCoder 1255(2015 Asia Beijing Regional Contest)
- HihoCoder 1257(2015 Asia Beijing Regional Contest)
- HihoCoder 1258(2015 Asia Beijing Regional Contest)
- 2014 Asia AnShan Regional Contest 题解
- 2014 ACM/ICPC Asia Regional Contest - B
- 2014 Asia AnShan Regional Contest (dp)
- 2014 Asia Shanghai Regional Contest J
- [LeetCode] Generate Parentheses
- C/C++中const关键字详解
- python处理音频文件(mp3)
- android 个人学习问题集
- ansible进阶小技巧(1)--tags
- 2014 Asia Beijing Regional Contest
- 自作的简单的DOS
- RouterOS的DNS设置说明
- 一段代码的感情色彩和心理活动
- Java基本功练习一(蒙特卡罗模拟,画出指定金字塔图形,分解质因数等)
- android 框架androidannotations在Eclipse中的配置
- 深入理解指针
- C# WinForm开发系列 - ToolBar/OutlookBar/Tab/Wizard
- 关于mysql大数据分页的一些方法。