POJ3186+3190+3250
来源:互联网 发布:js获取鼠标当前位置 编辑:程序博客网 时间:2024/06/05 15:45
The treats are interesting for many reasons:
- The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ can retrieve one treat from either end of his stash of treats.
- Like fine wines and delicious cheeses, the treats improve with age and command greater prices.
- The treats are not uniform: some are better and have higher intrinsic value. Treat i has value v(i) (1 <= v(i) <= 1000).
- Cows pay more for treats that have aged longer: a cow will pay v(i)*a for a treat of age a.
The first treat is sold on day 1 and has age a=1. Each subsequent day increases the age by 1.
Lines 2..N+1: Line i+1 contains the value of treat v(i)
513152
43
Five treats. On the first day FJ can sell either treat #1 (value 1) or treat #5 (value 2).
FJ sells the treats (values 1, 3, 1, 5, 2) in the following order of indices: 1, 5, 2, 3, 4, making 1x1 + 2x2 + 3x3 + 4x1 + 5x5 = 43.
题意:大体就是给出n个数,然后每次只能从首尾位置上选一个乘以当前出队的个数,求最大值
思路:直接来个模拟 求最大值 肯定是首尾位置上小的先出队 这样必然是最大值,
但是有一种情况难以解决 如果首尾位置 相等 还要继续往内收敛,
那么就没法解决了 这时候就有点觉着是动态规划了 好吧 我写不出来
一直拖到最后看了题解 感觉有点一点就通了 代码应该可以秒懂
- Source Code
/*#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<cmath>using namespace std;int main(){ int i,j,k; int n; int a[2001]; int vis[100001]; while(cin>>n) { for(i=0;i<n;i++) { cin>>a[i]; } j=0; k=n-1; long long ans=0; int num=1; memset(vis,0,sizeof(vis)); int flag=1; for(int m=0;m<n;m++) { flag=0; for(i=0;i<n;i++) { //cout<< vis[i]<<" "; if(vis[i]==0) { flag=1; } } //cout<<endl; if(flag==0)break; if(a[j]<a[k]&&vis[j]==0&&vis[k]==0) { vis[j]=1; ans+=(a[j]*num); num++; j++; } else if(a[k]<a[j]&&vis[j]==0&&vis[k]==0) { vis[k]=1; ans+=(a[k]*num); num++; k--; } } for(i=0;i<n;i++) { if(vis[i]==0) { ans+=(a[i]*num); break; } } cout<<ans<<endl; } return 0; }*/#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<cmath>using namespace std;int max(int a,int b){ return a>b?a:b; }int ans[2001][2001];int main(){ int i,j; int n; int a[2002]; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; for(i=n;i>0;i--) for(j=i;j<=n;j++) ans[i][j]=max(ans[i+1][j]+a[i]*(n+i-j),ans[i][j-1]+a[j]*(n+i-j)); cout<<ans[1][n]<<endl;}
Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.
Each cow i has a specified height hi (1 ≤ hi ≤ 1,000,000,000) and is standing in a line of cows all facing east (to the right in our diagrams). Therefore, cow i can see the tops of the heads of cows in front of her (namely cows i+1, i+2, and so on), for as long as these cows are strictly shorter than cow i.
Consider this example:
== == - = Cows facing right -->= = == - = = == = = = = =1 2 3 4 5 6
Cow#1 can see the hairstyle of cows #2, 3, 4
Cow#2 can see no cow's hairstyle
Cow#3 can see the hairstyle of cow #4
Cow#4 can see no cow's hairstyle
Cow#5 can see the hairstyle of cow 6
Cow#6 can see no cows at all!
Let ci denote the number of cows whose hairstyle is visible from cow i; please compute the sum of c1 through cN.For this example, the desired is answer 3 + 0 + 1 + 0 + 1 + 0 = 5.
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow i.
610374122
5题意:一周之前刚写过这个 再写一次吧
向右寻找比当前位置低的 碰到高的则更新位置为下一个 求一个总和
思路:
首先第一个元素入队,然后找到比他小的入队,如果第三个比第二个大,则更新二号位置,ans里记下下表即可,每次入队的元素逗比前面小,每次加上的num值包含前面所有比他高的数的个数
- Source Code
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int map[80001];int main(){ int i,j; int n,num,x; long long ans; while(cin>>n) { memset(map,0,sizeof(map)); num=0; ans=0; for(i=1;i<=n;i++) { cin>>x; while(num>0&&map[num]<=x) { num--; } ans+=num; num++; map[num]=x; } cout<<ans<<endl; } return 0; }
Help FJ by determining:
- The minimum number of stalls required in the barn so that each cow can have her private milking period
- An assignment of cows to these stalls over time
Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.
Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.
51 102 43 65 84 7
412324
Here's a graphical schedule for this output:
Time 1 2 3 4 5 6 7 8 9 10Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..Stall 3 .. .. c3>>>>>>>>> .. .. .. ..Stall 4 .. .. .. c5>>>>>>>>> .. .. ..Other outputs using the same number of stalls are possible.
还一度怀疑样例出错了 提示愣是看不懂 细心看了看 才领悟
n头牛挤奶,每头牛都有一个时间段,一台机器只能为一头牛挤奶,问你最少需要几台机器
后面分别是是那一台机器榜这头牛挤奶的
看样例 因为2 4 4 7这两头牛没有重复的区间
所以两头牛相当于公用一台机器
理解这点就有点絮头了
思路:单纯的最少的机器很好解决
但是机器的标号问题让人很伤脑筋
对于每个新进来的牛 若是他开始的时间在前面结束的后面 则说明两头牛可以共用
反之 则机器的数量上需要+1 并且新来的需要用当前加的这台机器
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
struct node
{
int l;
int e;
int c;
bool friend operator<(node A,node B)
{
if(A.e==B.e)
return A.l>B.l;
return A.e>B.e;
}
}d[60000];
priority_queue<node>q;
int num[50001];
bool cmp(node A,node B)
{
if(A.l==B.l)
return A.e<B.e;
return A.l<B.l;
}
int main()
{
int n;
int i,j;
int ans=1;
cin>>n;
for(i=1;i<=n;i++)
{
scanf("%d %d",&d[i].l,&d[i].e);
d[i].c=i;
}
sort(d+1,d+n+1,cmp);
q.push(d[1]);
num[d[1].c]=1;
for(i=2;i<=n;i++)
{
node temp;
temp=q.top();
int x=temp.e;
if(x<d[i].l)
{
num[d[i].c]=num[temp.c];
q.pop();
}
else
{
ans++;
num[d[i].c]=ans;
}
q.push(d[i]);
}
cout<<ans<<endl;
for(i=1;i<=n;i++)
cout<<num[i]<<endl;
}
- POJ3186+3190+3250
- poj3186
- POJ3186
- poj3186 dp
- dp poj3186
- poj3186(搜索)
- poj3186解题报告
- poj3186(递推)
- POJ3186【区间DP】
- POJ3186迷之DP
- poj3186(区间dp)
- POJ3186:Treats for the Cows
- poj3186 Treats for the Cows
- POJ3186 Treats for the Cows
- poj3186(记忆化搜索)
- POJ3186:Treats for the Cows(区间DP)
- POJ3186——Treats for the Cows
- POJ3186:Treats for the Cows 区间DP
- java中static 关键字
- Valid Parentheses
- 设置状态栏和应用颜色统一时,重叠
- python使用qq发邮件
- 【JZOJ5336】【NOIP2017提高模拟】提米树(DP、前缀和)
- POJ3186+3190+3250
- gitbook电子书制作步骤(linux环境下)
- hdu6168
- intellij 下Hibernate 的helloWorld
- C#基础-010 数据类型转换 -隐式类型转换/强制类型转换
- Swagger简介
- SpringMVC实现文件的上传和下载
- English in August(2017)
- Web Colors UVALive