2021-09-22每日刷题打卡

一、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 问题描述

img

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. 超标

四、参考文章

  1. USACO FEB 2002 CowCycling(奶牛玩具车队赛)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值