A - Couple doubi
这种题不要想复杂,直接找规律。找不出规律就打表找规律
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("! ") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf(" ") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int k,p; int main() { int i,j,kase=0; while(sf("%d%d",&k,&p)==2) { if(k/(p-1)%2==1) pf("YES "); else pf("NO "); } }
B - ZCC Loves Codefires
贪心
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("! ") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf(" ") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int n; struct node { int t,a; double f; }p[100005]; int cmp(const node& x,const node& y) { return x.f<y.f;} int main() { int i,j,kase=0; while(sf("%d",&n)==1) { for(i=0;i<n;i++) sf("%d",&p[i].t); for(i=0;i<n;i++) { sf("%d",&p[i].a); p[i].f = (double)p[i].t/p[i].a; } sort(p,p+n,cmp); long long sumt=0,res=0; for(i=0;i<n;i++) { sumt+=p[i].t; res+=p[i].a*sumt; } pf("%I64d ",res); } }
C - Magical Forest(HDU 4941)
双重MAP
D - Task
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <vector> #include <set> #include <map> typedef __int64 ll; const int N=100005; using namespace std; struct node { int x,y; }machine[N],tesk[N]; bool cmp(node a,node b) { if(a.x==b.x) return a.y>b.y; return a.x>b.x; } int main() { int n,m,i,j,k,num; ll money; int temp[105]; while(~scanf("%d%d",&n,&m)) { for(i=0;i<n;i++) scanf("%d%d",&machine[i].x,&machine[i].y); for(i=0;i<m;i++) scanf("%d%d",&tesk[i].x,&tesk[i].y); sort(machine,machine+n,cmp); sort(tesk,tesk+m,cmp); memset(temp,0,sizeof(temp)); for(i=0,j=0,money=0,num=0;i<m;i++) { while(machine[j].x>=tesk[i].x&&j<n)//标记符合时间条件的机器 { temp[machine[j].y]++; j++; } for(k=tesk[i].y;k<=100;k++)//判断是否有能完成测试的机器 { if(temp[k]) { temp[k]--; num++; money=money+500*tesk[i].x+2*tesk[i].y; break; } } } printf("%d %I64d ",num,money); } return 0; }
E - Stupid Tower Defense
dp,分析见:http://blog.csdn.net/u012860063/article/details/38520673
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("! ") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf(" ") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue LL dp[1510][1510]; int main() { int i,j,kase=0,T; sf("%d",&T); while(T--) { LL n,x,y,z,t; sf("%I64d%I64d%I64d%I64d%I64d",&n,&x,&y,&z,&t); LL ans = n*x*t; for(i=1;i<=n;i++) { for(j=0;j<=i;j++) { if(j==0) dp[i][j] = dp[i-1][j]+(i-1)*y*t; else dp[i][j] = max(dp[i-1][j]+(i-j-1)*y*(t+z*j), dp[i-1][j-1]+(i-j)*y*(t+z*(j-1))); ans = max(ans,dp[i][j]+(n-i)*(x+y*(i-j))*(t+z*j)); } } pf("Case #%d: %I64d ",++kase,ans); } }