SDNU Warming up for Team Selection

A - An ant's story

HDU - 3343                    
Long long ago, there is an ant crawling on an L-meter magic rubber band with speed of v cm/s.The magic rubber band will elongate m meters every second. We can assume that the magic rubber band elongates equably. Now, the ant is on the start point and crawling to another point, please tell me whether it can reach the endpoint.

InputThe first line of the input is T, which stands for the number of test cases you need to solve.
Each case include three integers: L , v , m ( 0< L< 10^9,0<= v, m< 10^ 9,).OutputFor each test case, if the ant can reach endpoint, output "YES", otherwise "NO".Sample Input
1
99999 61 1
Sample Output
YES

这道题有点坑这么简单竟然做了两个多小时。
这道题就是考数学的积分
晕死,这是一道 数学题

蚂蚁速度v cm/s,蝇长L;每秒蝇长增m;
第一秒: 蚂蚁走了蝇长的0.01*v/(L+m);
第二秒: 蚂蚁走了蝇长的0.01*v/(L+2*m);
第三秒:蚂蚁走了蝇长的0.01*v/(L+3*m);
第四秒:蚂蚁走了蝇长的0.01*v/(L+4*m);
第t秒:蚂蚁走了蝇长的0.01*v/(L+t*m);
把以上结果加起来,求积分,∫0.01*v/(L+t*m)dt=0.01*(v/m)*ln(L+t*m)+C
从0积到t0,=0.01*(v/m)*ln[(L+t0*m)/L].
只要0.01*(v/m)*ln[(L+t0*m)/L] 大于等于1(即蝇长)即表示可以走到终点。

如果v取0,即在原点踏步。不能达到终点。
L,m都是正常数,如果v取正常数,只要t0取很大的数,总能使式子0.01*(v/m)*ln[(L+t0*m)/L]大于1。

#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define ll long long
using namespace std;

int main(void) {
    int T, l, v, m;
    cin >> T;
    while(T--) {
        cin >> l >> v >> m;
        if(v > 0)
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

B - War Chess HDU - 3345

War chess is hh's favorite game:
In this game, there is an N * M battle map, and every player has his own Moving Val (MV). In each round, every player can move in four directions as long as he has enough MV. To simplify the problem, you are given your position and asked to output which grids you can arrive.

In the map:
'Y' is your current position (there is one and only one Y in the given map).
'.' is a normal grid. It costs you 1 MV to enter in this gird.
'T' is a tree. It costs you 2 MV to enter in this gird.
'R' is a river. It costs you 3 MV to enter in this gird.
'#' is an obstacle. You can never enter in this gird.
'E's are your enemies. You cannot move across your enemy, because once you enter the grids which are adjacent with 'E', you will lose all your MV. Here “adjacent” means two grids share a common edge.
'P's are your partners. You can move across your partner, but you cannot stay in the same grid with him final, because there can only be one person in one grid.You can assume the Ps must stand on '.' . so ,it also costs you 1 MV to enter this grid.

这道题做的真难受,一直超时。这道题应该在进入之前就把mv值减了,因为如果放入队列之后,弹出之后再减就不能够保证到达每一步的mv值最大,优先队列就保证了出来的mv值一直是最大的。还有一个坑就是在输入的时候不能判断是不是e,因为这样会把把所有的点遍历。而放入函数中的话就不用遍历所有的点,只是用到哪个点就判断周围是否有敌人。

D - Calculate the expression

HDU - 3347                    

You may find it’s easy to calculate the expression such as:
a = 3
b = 4
c = 5
a + b + c = ?
Isn’t it?

InputThe first line contains an integer stands for the number of test cases.
Each test case start with an integer n stands for n expressions will follow for this case.
Then n – 1 expressions in the format: [variable name][space][=][space][integer] will follow.
You may suppose the variable name will only contain lowercase letters and the length will not exceed 20, and the integer will between -65536 and 65536.
The last line will contain the expression you need to work out.
In the format: [variable name| integer][space][+|-][space][variable name| integer] …= ?
You may suppose the variable name must have been defined in the n – 1 expression and the integer is also between -65536 and 65536.
You can get more information from the sample.
OutputFor each case, output the result of the last expression.Sample Input
3
4
aa = 1
bb = -1
aa = 2
aa + bb + 11 = ?
1
1 + 1 = ?
1
1 + -1 = ?
Sample Output
12
2
0
#include<cstdio>
#include<cstring>
using namespace std;

struct abc
{
    int num;
    char s[25];
}abc[1000000];

int change(int len, char s[] )
{
    int ans=0, a, c=1;
    if(s[0]=='-')
    {
        for(int i=len-1; i>0; i--)
        {
            a=(s[i]-'0')*c;
            ans+=a;
            c*=10;
        }
        return -ans;
    }
    for(int i=len-1; i>=0; i--)
    {
        a=(s[i]-'0')*c;
        ans+=a;
        c*=10;
    }
    return ans;
}
int main()
{
    int t, n, ans=0;
    char z, k[25];
    int flag = 0;
    scanf("%d", &t);
    while(t--)
    {
        memset(k, 0, sizeof(k));
        ans=0;
        scanf("%d", &n);
        for(int i=0; i<n-1; i++)
        {
            scanf("%s = %d", abc[i].s, &abc[i].num);
            //printf("%s =  %d\n",abc[i].s,abc[i].num );
        }
        while(scanf("%s %c ", k, &z))
        {

            if(k[0]>='a' && k[0]<='z')
            {
                for(int i=n-1; i>=0; i--)
                {
                    if(k[0]!=abc[i].s[0])
                        continue;
                    else if(!strcmp(k, abc[i].s))
                    {
                        if(flag)
                        {
                            ans-=abc[i].num;
                            flag = 0;
                        }
                        else
                            ans += abc[i].num;
                             if(z == '-')
                            flag = 1;

                        //printf("abc[i].num= %d\n",abc[i].num );
                        break;
                    }
                }
            }
            else
            {//printf("csdcasd\n");
                int len=strlen(k);
                        if(flag)
                        {
                            ans-=change(len, k);
                            flag = 0;
                        }
                        else
                           ans+=change(len, k);
                    if(z == '-')
                    flag = 1;

            }
            if(z=='=')
                break;
        }
        scanf("%c", &z);
        printf("%d\n", ans);

    }
    return 0;
}

E - coins

HDU - 3348

"Yakexi, this is the best age!" Dong MW works hard and get high pay, he has many 1 Jiao and 5 Jiao banknotes(纸币), some day he went to a bank and changes part of his money into 1 Yuan, 5 Yuan, 10 Yuan.(1 Yuan = 10 Jiao)
"Thanks to the best age, I can buy many things!" Now Dong MW has a book to buy, it costs P Jiao. He wonders how many banknotes at least,and how many banknotes at most he can use to buy this nice book. Dong MW is a bit strange, he doesn't like to get the change, that is, he will give the bookseller exactly P Jiao.
Input T(T<=100) in the first line, indicating the case number.
T lines with 6 integers each:
P a1 a5 a10 a50 a100
ai means number of i-Jiao banknotes.
All integers are smaller than 1000000. Output Two integers A,B for each case, A is the fewest number of banknotes to buy the book exactly, and B is the largest number to buy exactly.If Dong MW can't buy the book with no change, output "-1 -1". Sample Input
3
33 6 6 6 6 6
10 10 10 10 10 10
11 0 1 20 20 20
Sample Output
6 9
1 10
-1 -1

AC代码
这道题最重要的是转换的思想,把求最大值转化为最小值。第一种方法转化的思想是从小面值到大面值一直给钱,当此时可以满足此面值的钱可以完全给足p,并且有余时,此时就把问题转化为,把给多的这部分要用最小的张数抽出来。
第二种方法直接就把最大值的求法转化为最小值的求法。


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
struct banknotes
{
    int num;
    int money;
}a[10];
void init()
{
    memset(a,0,sizeof(a));
    a[1].money = 1;
    a[2].money = 5;
    a[3].money = 10;
    a[4].money = 50;
    a[5].money = 100;

}
int main()
{
    int t;
    scanf("%d", &t);
    while(t --)
    {
        init();
        int p;
        scanf("%d", &p);
        for(int i = 1; i <= 5; i ++)
        {
            scanf("%d", &a[i].num);
        }
        int Min = 0;
        int Max = 0;
        int x = p;
        for(int i = 5;i >= 1; i --)
        {
            if(!(x % a[i].money)&&(a[i].num > (x / a[i].money)))
            {
                Min += (x / a[i].money);
                x = 0;
                break;
            }
            if(a[i].num*a[i].money > x)
            {
                int tem = x % a[i].money;
                Min += (x / a[i].money);
                x = tem;
            }
            else
            {
                x -= a[i].money*a[i].num;
                Min += a[i].num;
            }
        }
          if(x)
             Min = -1;
          x = p;
          int b[6] = {0};
          for(int i = 1; i <= 5; i ++)
          {
               if(!(x % a[i].money)&&(a[i].num > (x / a[i].money)))
            {
                b[i] += (x / a[i].money);
                a[i].num -= (x / a[i].money);
                x = 0;
                break;
            }
            if(a[i].num*a[i].money > x)
            {
                b[i] += (x / a[i].money + 1);
                a[i].num -= (x / a[i].money + 1);
                x %= a[i].money;
                x -= a[i].money;
                int n = -x;
                for(int j = i - 1; j >= 1; j --)
                {
                    if(n >= a[j].money&&b[j] > 0)
                    {
                        n -= a[j].money;
                        b[j] --;
                        a[j].num ++;
                        if(n == 0)
                    {
                        x = 0;
                        break;
                    }
                        j ++;
                    }
                }
            } else
            {
                b[i] += a[i].num;
                x = x - a[i].num*a[i].money;
                a[i].num = 0;
            }
            if(!x)
                break;
          }
          if(x)
            Max = -1;
          else
            Max = b[1] + b[2] + b[3] + b[4] + b[5];
             printf("%d %d\n", Min, Max);
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
struct banknotes
{
    int num;
    int money;
}a[10];
void init()
{
    memset(a,0,sizeof(a));
    a[1].money = 1;
    a[2].money = 5;
    a[3].money = 10;
    a[4].money = 50;
    a[5].money = 100;

}
int getmin(int p)
{
    int Min = 0;
    int x = p;
        for(int i = 5;i >= 1; i --)
        {
            if(!(x % a[i].money)&&(a[i].num > (x / a[i].money)))
            {
                Min += (x / a[i].money);
                x = 0;
                break;
            }
            if(a[i].num*a[i].money > x)
            {
                int tem = x % a[i].money;
                Min += (x / a[i].money);
                x = tem;
            }
            else
            {
                x -= a[i].money*a[i].num;
                Min += a[i].num;
            }
        }
          if(x)
             Min = -1;
             return Min;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t --)
    {
        init();
        int p;
        scanf("%d", &p);
        int sum = 0;
        int numsum = 0;
        for(int i = 1; i <= 5; i ++)
        {
            scanf("%d", &a[i].num);
            sum += a[i].num*a[i].money;
            numsum += a[i].num;
        }
        int k = sum - p;
        int ansmin = getmin(p);
        int ansmax = numsum - getmin(k);
         if(ansmin == -1)
            ansmax = -1;
             printf("%d %d\n", ansmin, ansmax);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值