Welcome, Guest! Sign Up RSS

Clever Space

Friday, 11.22.2024
Main » 2013 » September » 29

水题

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define N 100010
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
int dp[N];
int main()
{
  int n,i,p,t,x;
  scanf("%d",&n);
  int ans=0;
  FOR(i,1,n)
  {
    scanf("%d %d",&p,&t);
    dp[p]=0;
    for (scanf("%d",&x);x>0;scanf("%d",&x)) dp[p]=max(dp[p],dp[x]);
    dp[p]+=t;
Views: 328 | Added by: dhy0077 | Date: 09.29.2013

想出来了……
dp[i][j]表示修前i个路面,最大/最小的值是a[j]的最小花费

正反做两遍

Code:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define INF 2147000000
#define N 2010
typedef long long LL;
using namespace std;
int a[N],f[N][N],b[N];
int main()
{
  int n,i,j;
  scanf("%d",&n);
  FOR(i,1,n) {scanf("%d",&a[i]);b[i]=a[i];}
  sort(b+1,b+1+n);
  FOR(i,0,n) f[i][0]=INF;
  FOR(i,1,n) FOR(j,1,n) f[i][j]=min(f[i][j-1 ... Read more »
Views: 475 | Added by: dhy0077 | Date: 09.29.2013

搬运问题及相对位移

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define N 100010
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
int x[N],y[N];
int main()
{
  int n,i;
  scanf("%d",&n);
  FOR(i,1,n) scanf("%d %d",&x[i],&y[i]);
  sort(y+1,y+1+n);
  int p=n/2+1;
  int ans=0;
  FOR(i,1,n) ans+=abs(y[i]-y[p]);
  sort(x+1,x+1+n); 
  FOR(i,1,n) x[i]-=i-1;
  ... Read more »
Views: 347 | Added by: dhy0077 | Date: 09.29.2013

指针法

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define N 100010
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
int a[N],b[N],c[N];
int main()
{
  int n,m,i,j;
  scanf("%d %d",&n,&m);
  LL sum=0;int len=0,tot=0;
  FOR(i,1,n) scanf("%d",&a[i]);
  FOR(i,1,m) scanf("%d",&b[i]);
  sort(a+1,a+1+n);sort(b+1,b+1+m);
  i=1,j=0;
  FOR(i,1,n)< ... Read more »
Views: 340 | Added by: dhy0077 | Date: 09.29.2013

简单DP+贪心

... Read more »
Views: 361 | Added by: dhy0077 | Date: 09.29.2013

二进制拆包

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define N 1000010
#define M 30010
typedef long long LL;
using namespace std;
int W[N],P[N];
int dp[M];
int main()
{
  int n,T,i,m,t,p,j;
  scanf("%d %d",&n,&T);
  int len=0,sum=0;
  FOR(i,1,n) 
  {
    scanf("%d %d %d",&m,&t,&p);
    sum+=m*p;
    if (m*t>T) m=T/t;< ... Read more »
Views: 280 | Added by: dhy0077 | Date: 09.29.2013