一、POJ-1946:Cow Cycling
1.1 问题描述
The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determine a race strategy which will get one of them across the finish line as fast as possible.
Like everyone else, cows race bicycles in packs(成群结队地骑车) because that’s the most efficient way to beat the wind. While travelling at x laps/minute (x is always an integer), the head of the pack expends x*x energy/minute while the rest of pack drafts behind him using only x energy/minute. Switching leaders (切换领导)requires no time though can only happen after an integer number of minutes. Of course, cows can drop out of the race at any time.
The cows have entered a race D (1 <= D <= 100) laps long. Each cow has the same initial energy, E (1 <= E <= 100).
What is the fastest possible finishing time? Only one cow has to cross the line(过线). The finish time is an integer. Overshooting the line during some minute is no different than barely reaching it at the beginning of the next minute (though the cow must have the energy left to cycle the entire minute). N, D, and E are integers.
题目大意:
有n头牛,每头都有能量e,要跑d圈,跑得过程中每分钟跑x圈(自己选择),领头的消耗x*x的能量,其他的消耗x的能量,问跑完d圈最少需要多少时间。
1.2 问题解决
#include<iostream>
using namespace std;
int dp[32][128][128];
int main()
{
int n,e,d,i,j,k,a;
scanf("%d%d%d",&n,&e,&d);
for(i=0;i<=n;++i)
for(j=0;j<=d;++j)
for(k=0;k<=e;++k)
dp[i][j][k]=INT_MAX;
dp[1][0][0]=0;
for(i=1;i<=n;++i)
for(j=0;j<d;++j)
for(k=0;k<=e;++k)
if(dp[i][j][k]!=INT_MAX){
for(a=0;a+j<=d&&k+a*a<=e;++a)
dp[i][j+a][k+a*a]=min(dp[i][j+a][k+a*a],dp[i][j][k]+1);
if(i<n)
dp[i+1][j][j]=min(dp[i+1][j][j],dp[i][j][k]);
}
int ans=INT_MAX;
for(i=0;i<=e;++i)
ans=min(ans,dp[n][d][i]);
if(ans==INT_MAX)
printf("0");
else
printf("%d",ans);
return 0;
}
二、Leetcode-141:环形链表
2.1 问题描述
2.2 问题解决
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public boolean hasCycle(ListNode head) {
Set<ListNode> set = new HashSet<>();
while(head != null)
{
if(!set.add(head))
return true;
head = head.next;
}
return false;
}
}
三、生词
strategy n. 策略
packs n. 包裹
lap n. 圈
draft n. 草稿
overshoot v. 超标