2020HDU多校第四场

1002 贪心

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi 3.141592654
typedef long long ll;
const int N = 2e6+5;
struct node{
    int a,d;
    int ti;
}w[1005];
int cmp(node x,node y){
    return x.ti <y.ti;
}
int main(){
    int t,n,x,y;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i = 1 ; i <= n ; i++){
            scanf("%d %d",&w[i].a,&w[i].d);
            if(w[i].a == 100)
                w[i].ti = 0;
            else{
                w[i].ti = (100+w[i].a-1)/w[i].a;
                w[i].ti = (w[i].ti -1) * w[i].d;
            }
        }
        sort(w+1,w+1+n,cmp);
        int now = w[1].ti;
        double p = 0,s = 1.0/n;
        for(int i = 1 ; i <= n ; i++){
            if(w[i].ti == now)  p += 0.5 * s;
            else                p += s;
        }
        printf("%.6f\n",p);
    }
    return 0;
}

1004 最短路问题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100000
#define INF 999999999999999
struct edge
{
    int next;
    int to;
    ll w;
}e[N*4*8+50];
int head[N*3+50],bian;
void add(int x,int y,ll w)
{
    bian++;
    e[bian].next=head[x];
    head[x]=bian;
    e[bian].to=y;
    e[bian].w=w;
}
char ch[N*3+50];
struct hh
{
    int d;
    ll w;
};
ll mi(ll a,ll b)
{
    if(a<b)
        return a;
    return b;
}
ll adj[N*3+50],en[N*3+50];
ll n,m,s,ts,xs,cnt;
bool operator<(hh a,hh b)
{
    return a.w>b.w;
}
void dijike(int x)
{
   priority_queue<hh>q;
    //memset(en,0,sizeof(en));
    for(int i=0;i<=n+cnt;i++)
    {

        adj[i]=999999999999999;
        en[i]=0;
    }
    adj[x]=0;
    hh u;
    u.d=x;
    u.w=0;
    q.push(u);
    while(!q.empty())
    {
        int to=(q.top()).d;
        if(to==n+cnt)
            break;
        q.pop();
        if(en[to])
        continue;
        en[to]=1;
        for(int i=head[to];i!=-1;i=e[i].next)
        {
            int y=e[i].to;
            if(en[y]==1)
                continue;
            if(adj[y]>adj[to]+e[i].w)
            {
                adj[y]=adj[to]+e[i].w;
                hh tt;
                tt.d=y;
                tt.w=adj[y];
                q.push(tt);
            }
        }
    }
}
int sh[N*3+50];
int main()
{
    int z;
    scanf("%d",&z);
    while(z--)
    {
        bian=-1;
        scanf("%lld%lld%lld%lld%lld",&n,&m,&s,&ts,&xs);
        scanf("%s",ch+1);
        cnt=0;
       // memset(head,-1,sizeof(head))
        for(int i=1;i<=n;i++)
        {
             sh[i]=0;
             if(ch[i]=='M')
             {
                 cnt++;
                 sh[i]=cnt+n;
                 ch[cnt+n]='R';
                 ch[i]='L';
             }
        }
           for(int i=0;i<=cnt+n+1;i++)
            head[i]=-1;
       for(int i=1;i<=m;i++)
       {
           int a,b;
           ll c;
           scanf("%d%d%lld",&a,&b,&c);

               if(ch[a]==ch[b])
               {
                   add(a,b,c);
                   add(b,a,c);
               }
               else
               {
                   add(a,b,c+xs);
                   add(b,a,c+xs);
               }
                if(sh[a]!=0)
                {
                    if(ch[sh[a]]==ch[b])
                    {
                           add(sh[a],b,c);
                           add(b,sh[a],c);
                    }
                    else
                    {
                         add(sh[a],b,c+xs);
                         add(b,sh[a],c+xs);
                    }
                }
                 if(sh[b]!=0)
                {
                    if(ch[a]==ch[sh[b]])
                    {
                           add(a,sh[b],c);
                           add(sh[b],a,c);
                    }
                    else
                    {
                          add(a,sh[b],c+xs);
                          add(sh[b],a,c+xs);
                    }
                }
                if(sh[a]!=0&&sh[b]!=0)
                {
                    int aa=sh[a],bb=sh[b];
                     if(ch[aa]==ch[bb])
                       {
                           add(aa,bb,c);
                           add(bb,aa,c);
                       }
                       else
                       {
                           add(aa,bb,c+xs);
                           add(bb,aa,c+xs);
                       }
                }

       }
       ll mii=INF;
        cnt++;
        add(ts,cnt+n,0);
        add(cnt+n,ts,0);
        if(sh[ts]!=0)
        {
            add(sh[ts],cnt+n,0);
            add(cnt+n,sh[ts],0);
        }
        add(0,s,0);
        add(s,0,0);
        if(sh[s]!=0)
        {
            add(0,sh[s],0);
            add(sh[s],0,0);
        }
        // for(int i=0;i<=cnt+n;i++)
       // {
           // printf("i=%d,adj=%lld\n",i,adj[i]);
       // }
        dijike(0);
       // for(int i=0;i<=cnt+n;i++)
       // {
           // printf("i=%d,adj=%lld\n",i,adj[i]);
       // }
       printf("%lld\n", adj[cnt+n]);
    }
}

1011 公式

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double g = 6.67430e-11;
ll qpow(ll base, ll n){ll ans = 1; while (n){if (n & 1) ans = ans * base % mod; base = base * base % mod; n >>= 1;} return ans;}
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
int main(){
	int cas;
	cin >> cas;
	while (cas --){
		double a, b, d, t;
		scanf("%lf %lf %lf %lf", &a, &b, &d, &t);
		double x = g * b / (d * d);
		double y = g * a / (d * d);
		double sa = 0.5 * x * t * t;
		double sb = 0.5 * y * t * t;
		//printf("%.20f\n", sa + sb);
		double ans = d  - (sa + sb)*0.001;
		printf("%.30f\n", ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值