T1 题目描述:
1999. Wexley接苹果(apple)
(File IO): input:apple.in output:apple.out时间限制: 1000 ms 空间限制: 128000 KB 具体限制Goto ProblemSet
思路:贪心模拟,使每次移动数尽量少即可.难度较容易。
附上AC代码:(考试完了重新码的,考试的时候的代码有点小问题)
#include <cstdio> #include <iostream> using namespace std; int n,m,k,a[21]; int b[21],head,ans,tmp; int main() { freopen("apple.in","r",stdin); freopen("apple.out","w",stdout); scanf("%d %d",&n,&m); scanf("%d",&k); b[0]=1; for(int i=1;i<=k;i++) { scanf("%d",&a[i]); } head=m; for(int i=1;i<=k;i++) { if(head>=a[i] && (head-m+1)<=a[i]) continue; if(head<a[i]) { ans+=a[i]-head; head+=a[i]-head; continue; } if((head-m+1)>a[i]) { int tmp=head; head=a[i]+m-1; ans+=tmp-head; continue; } } printf("%d",ans); }
T2
2000. 【2015.8.6普及组模拟赛】Leo搭积木(brick)
(File IO): input:brick.in output:brick.out时间限制: 1000 ms 空间限制: 128000 KB 具体限制
思路:标答:动态规划。
骗分:暴力DFS.
附上DFS30分代码TLE
#include <cstdio> #include <iostream> using namespace std; int n,a[3002][3],ans=0,mina; const int inf=999999999; void swap(int a,int b) { int c=b; b=a; a=c; } void dfs(int l,int w,int high) { if(high>ans) ans=high; if(w==mina) { return; } for(int i=1;i<=n;i++) { if(a[i][0]<l && a[i][1]<w) dfs(a[i][0],a[i][1],high+a[i][2]); if(a[i][0]<w && a[i][1]<l) dfs(a[i][1],a[i][0],high+a[i][2]); if(a[i][0]<l && a[i][2]<w) dfs(a[i][0],a[i][2],high+a[i][1]); if(a[i][0]<w && a[i][2]<l) dfs(a[i][2],a[i][0],high+a[i][1]); if(a[i][1]<l && a[i][2]<w) dfs(a[i][1],a[i][2],high+a[i][0]); if(a[i][1]<w && a[i][2]<l) dfs(a[i][2],a[i][1],high+a[i][0]); if(a[i][1]>l && a[i][2]>w) continue; } } int main(){ freopen("brick.in","r",stdin); freopen("brick.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++) { int a1,b1,c1; scanf("%d %d %d",&a1,&b1,&c1); if(c1>b1) swap(c1,b1); if(a1<b1) swap(a1,b1); if(c1>b1) swap(c1,b1); if(mina>c1) mina=c1; a[i][0]=a1;a[i][1]=b1;a[i][2]=c1; } dfs(inf,inf,0); printf("%d",ans); }
100分代码:
#include <cstdio> #include <algorithm> #include <cstring> struct Node{ int w,l,h; }a[10001]; int Max(int a,int b) { if(a>b) return a; return b; } int Min(int a,int b) { if(a>b) return b; return a; } bool bdx(Node c,Node d) { return c.l<d.l; } int main() { freopen("brick.in","r",stdin); freopen("brick.out","w",stdout); int n,f[10001],ans; scanf("%d",&n); int o,p,q; for(int i=1;i<=n;i++) { scanf("%d %d %d",&o,&p,&q); a[i].l=Max(o,p);a[i].w=Min(o,p);a[i].h=q; a[i+n].l=Max(o,q);a[i+n].w=Min(o,q);a[i+n].h=p; a[i+2*n].l=Max(p,q);a[i+2*n].w=Min(p,q);a[i+2*n].h=o; } std::sort(a+1,a+3*n+1,bdx); for(int i=1;i<=3*n;i++) f[i]=a[i].h; for(register int i=3*n;i>=1;i--) for(register int j=i+1;j<=3*n;j++) if(a[i].w<a[j].w && a[i].l != a[j].l) f[i]=Max(f[j]+a[i].h,f[i]); for(int i=1;i<=3*n;i++) ans=Max(ans,f[i]); printf("%d",ans); }
T4
2002. 【2015.8.6普及组模拟赛】Leopard学霸(study)
(File IO): input:study.in output:study.out时间限制: 1000 ms 空间限制: 128000 KB 具体限制
思路:标答:最小堆
接近标答:贪心。
附上80分贪心代码(TLE+RE)
#include <cstdio> #include <algorithm> #define rr register bool time[100001],bj; struct Node{ int di,pi; }a[100001]; inline bool bdx(Node c,Node d) { return c.pi>d.pi; } int main() { freopen("study.in","r",stdin); freopen("study.out","w",stdout); rr long long ans=0LL; rr int n,mark=0; scanf("%d",&n); for(rr int i=1;i<=n;i++) scanf("%d %d",&a[i].di,&a[i].pi); std::sort(a+1,a+n+1,bdx); for(rr int i=1;i<=n;i++) { if(!time[a[i].di]) { time[a[i].di]=true; ans+=a[i].pi; } else { rr int j=a[i].di; while(time[j]) j--; if(j<1) continue; ans+=a[i].pi; time[j]=true; } } printf("%lld",ans); }
目前这道题还没AC...