HDU 第四场部分题解:

1002:
是个很简单的题,mh队友,在策略上有点问题,但显然策略范围很小,然后我提议对策略进行暴力,然后成功A掉

参考代码:

#include<stack>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<char,int>pii;
const int maxn=2e5+5;
const int eps=1e-6;
struct shudui
{
    double a,d;
}m[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
        {
            scanf("%lf%lf",&m[i].a,&m[i].d);
        }
        double temp=1.0/(n*1.0);
        double temp_pai=temp/2.0;
        double ans=temp_pai;

        for(int i=1;i<=n;++i)
        {
            double result=temp_pai;
            for(int j=1;j<=n;++j)
            {
                if(j==i) continue;
                int tt1=0,tt2=0,live=100;
                while(live>0)
                {
                    live-=m[i].a;
                    if(live<=0) break;
                    tt1+=m[i].d;
                }
                live=100;
                while(live>0)
                {
                    live-=m[j].a;
                    if(live<=0) break;
                    tt2+=m[j].d;
                }

                if(tt1==tt2)
                {
                    result+=temp_pai;
                }
                else if(tt1<tt2)
                    result+=temp;
            }
            if(result-ans>eps) ans=result;
        }
        printf("%lf\n",ans);
    }
    return 0;
}

1011:
该场最简单的一题,但是又很唬人,可能经验不够丰富,我和mh队友一直进行讨论咋咋求,但是想不出来,之后我嫖到数据的精度成功A掉,显然这种数据范围,随便找造一个可靠点的数据是可以飘过去的

参考代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
const int maxn = 1e5 + 5;
map<string, int> mp;
int pre[maxn], vis[30];
//char dp[maxn];
vector<ll> vec;
// typedef pair<char, int> p;
// stack<p> q;
// int a[maxn], sum[maxn];
// char pc[maxn];
// char s[maxn];
int dp[maxn][10], cnt;
struct node
{
    double a, b;
} p[maxn];
bool check(double a, double b, double c, double d)
{
    double q1 = 0, q2 = 0, e = 100, f = 100;
    while (e > 0 && f > 0)
    {
        if (q1 == 0)
            e -= a, q1 = b;
        if (q2 == 0)
            f -= c, q2 = d;
        q1--, q2--;
    }
    if ((e <= 0 && f <= 0) || (e > 0))
        return true;
}
int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    double g = 6.67430, ans = 0.00000000001;
    g *= ans;
    int t;
    cin >> t;
    while (t--)
    {
        double a, b, d, m, c, k;
        cin >> a >> b >> d >> m;
        c = d;
        if (a > b)
            k = a;
        else
            k = b;
        d = (double(1.0) / d / k) * (double(1.0) / d / k);
        m *= m;
        double dis1 = double(0.5) * (g * a * d * double(4.0)) * m;
        double dis2 = double(0.5) * (g * b * d * double(4.0)) * m;
        printf("%.11lf\n", c - dis1 - dis2);
    }
}

1004
这题是个菲薄那切的题,一开始确实没有想到,中间的时候mh提了提,我没有细想,我感觉他的代码可行,然后让他去交,没想到wa了,然后我就没有往这方面想,之后我想到了组合数求逆元,显然是不对的,最后几分钟快要放弃的时候,浏览错误代码时,看到mh代码,发现wa点,改过A掉了
参考代码:

#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 5;
const ll mod = 1000000007;
ll fac[maxn];
ll inv[maxn];
ll n;
string a[maxn];
ll dp[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        ll ans = 0;
        memset(dp, 0, sizeof(dp));
        for (ll i = 1; i <= n; i++)
            cin >> a[i];
        for (ll i = 2; i <= n; i++)
        {
            if (a[i] == a[i - 1])
                dp[i] = dp[i - 1];
            else
                dp[i] = (dp[i - 1] + dp[i - 2] + 1) % mod;
        }
        cout << dp[n] + 1 << endl;
    }
}

猜你喜欢

转载自blog.csdn.net/yangzijiangac/article/details/107695497
今日推荐