HDU百题2050->2059

2050:折线分割平面

找规律得到递推公式 f(n+1)=f(n)+4n+1

参考博客:https://www.jianshu.com/p/3d692d9dd999

所有有规律的数都可以用oeis,比如直接输入2,7,16就会出来公式

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e4 +10;

int main()
{
    int c, n;
    cin>>c;
    int arr[maxn];
    arr[1] = 2;
    for(int i = 2; i < maxn; i++)
    {
        arr[i] = arr[i-1] + 4 * (i-1) + 1;
    }
    while(c--)
    {
        cin>>n;
        cout<<arr[n]<<endl;
    }

    return 0;
}

2051:Bitset

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e4 +10;

void bin(int n)
{
    int a[1000];
    int pos = 0;
    while(n)
    {
        a[pos++] = n&1;
        n >>= 1;
    }
    for(int i = pos-1; i >= 0; i--)
    {
        cout<<a[i];
    }
    cout<<endl;
}

int main()
{
    int n;
    while(cin>>n)
    {
        bin(n);
    }

    return 0;
}

2052:Picture
 

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e4 +10;

int main()
{
    int n, m;
    while(~scanf("%d%d", &n, &m))
    {
        for(int i = 0 ;i < n ; i++)
        {
            if(i == 0) cout<<'+';
            cout<<'-';
            if(i == n-1) cout<<'+';
        }
        cout<<endl;
        for(int i = 0; i < m; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if(j == 0) cout<<'|';
                cout<<' ';
                if(j == n-1)cout<<'|';
            }
            cout<<endl;
        }
        for(int i = 0 ;i < n ; i++)
        {
            if(i == 0) cout<<'+';
            cout<<'-';
            if(i == n-1)cout<<'+';
        }
        cout<<endl;
        cout<<endl;
    }
    return 0;
}

2053:Switch Game

筛选因子,对1特判就行了

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e4 +10;

int main()
{
    int n;
    while(cin>>n)
    {
        int pos = 0;
       for(int i = 2; i <= n/2; i++)
       {
           if(n%i == 0) pos++;
       }
       if(pos&1 || n == 1) cout<<1<<endl;
       else cout<<0<<endl;
    }
    return 0;
}

2054:A == B ?
这*题搞我,我开始写了一抹多判断就是交不过,然后看了看大佬的博客才发现大佬真的写的很易懂,先判断有无小数点,有的话从最后一位判断是否为0并去0,最后再把小数点去掉即可。

里面用到了一些string的函数,find()方法:查找字符串中是否含有某一字符。如果找不到不是返回-1,而是返回一个static成员-------string::npos。substr()方法:顾名思义,就是用来截取子串的。

参考博客:https://blog.csdn.net/guodongxiaren/article/details/24271603

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e4 +10;

void mix(string &s)
{
    int len = s.size();
    if(s.find('.') != string::npos)
    {
        for(int i = len-1;s[i] == '0'; i--)
        {
            len--;

        }
    }
    if(s[len-1] == '.') len--;
    s = s.substr(0,len);
}
int main()
{
    string a1, a2;
    while(cin>>a1>>a2)
    {
        mix(a1);
        mix(a2);
        if(a1 == a2)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }

    return 0;
}

2055:An easy problem

水。  

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = (int)1e5 +10;


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        char x;
        int y;
        cin>>x>>y;
        if(x >= 'A' && x <= 'Z')
            y += x-64;
        else
            y -= x-96;
        cout<<y<<endl;
    }
    return 0;
}



2056:Rectangles

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = (int)1e5 +10;


int main()
{
    double x1, y1, x2, y2, x3, y3, x4, y4;
    while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4)
    {
        if(x1>x2) swap(x1, x2);
        if(y1>y2) swap(y1, y2);
        if(x3>x4) swap(x3, x4);
        if(y3>y4) swap(y3, y4);//变成正对角线从小到大

        double minx = max(x1, x3);
        double maxx = min(x2, x4);
        double miny = max(y1, y3);
        double maxy = min(y2, y4);//确定相交面积的坐标

        if(minx > maxx || miny > maxy)
            cout<<"0.00"<<endl;
        else
            printf("%.2lf\n", (maxx - minx)*(maxy - miny));

    }

    return 0;
}



2057:A + B Again

不要想太多。

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = (int)1e5 +10;

int main()
{
    ll a, b;
    while(~scanf("%llX%llX", &a, &b))
    {
        if(a+b>=0)
            printf("%llX\n", a+b);
        else
            printf("-%llX\n", -(a+b));
    }

    return 0;
}



2058:The sum problem

求求自己别再把输入输出的%后的东西写错了!!!

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = (int)1e5 +10;

int main()
{
    ll n, m;
    while(scanf("%lld%lld", &n, &m), n||m)
    {
        ll a;
        int b = sqrt(2*m);
        for(int i = b; i > 0; i--)
        {
            a = 2*m + i - i*i;
            if(a%(2*i) == 0)
            printf("[%lld,%lld]\n", a/(2*i),a/(2*i)+i-1);
        }
        cout<<endl;
    }
    return 0;
}



2059:龟兔赛跑

简单dp,把状态转移想好就可以了

参考博客:https://blog.csdn.net/xxxslinyue/article/details/55519225

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = (int)1e5 +10;

int l, n, c, t, vr, vt1, vt2;
int arr[107];
double dp[107];
double ti;

int main()
{

    while(cin>>l)
    {
        cin>>n>>c>>t;
        cin>>vr>>vt1>>vt2;
        for(int i = 1; i <= n; i++)
            cin>>arr[i];
        ti = 1.0*l/vr;
        for(int i = 0 ;i < 107; i++)
        {
            dp[i] = INF;
        }
        dp[0] = 0;
        arr[n+1] = l;
//        if(vr > max(vt1, vt2)) cout<<"Good job,rabbit!"<<endl;
//        else if(vr < vt2) cout<<"What a pity rabbit!"<<endl;
//        else
//        {
            for(int i = 0; i <= n+1; i++)
            {
                for(int j = i+1; j <= n+1; j++)
                {
                    int x, y;
                    if(c>arr[j]-arr[i])
                    {
                        x = arr[j]-arr[i];
                        y = 0;
                    }
                    else
                    {
                        x = c;
                        y = arr[j]-arr[i]-c;
                    }
                    if(i == 0)
                        dp[j] = min(dp[j], dp[i]+x*1.0/vt1+y*1.0/vt2);
                    else
                        dp[j] = min(dp[j], dp[i]+t+x*1.0/vt1+y*1.0/vt2);
                }
            }
            if(dp[n+1] < ti)
                puts("What a pity rabbit!");
            else
                puts("Good job,rabbit!");
//        }

    }

    return 0;
}



 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值