zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 193

    A:

    题意:给出原价A和折扣价B,求打折的百分比数。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 #include <map>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <set>
    12 #include <cctype>
    13 using namespace std;
    14 typedef long long ll;
    15 typedef pair <int,int> pii;
    16 double a,b;
    17 int main(void)
    18 {
    19     scanf("%lf %lf",&a,&b);
    20     printf("%.6f",(a-b)/a*100);
    21     return 0;
    22 }

     

    B:

    题意:给出N个商店,到第i个商店需要时间Ai分钟,有Xi个游戏机,每个需要Pi钱,每分钟每个商店出售一个游戏机,求是否能买到游戏机以及最小花费。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 #include <map>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <set>
    12 #include <cctype>
    13 using namespace std;
    14 typedef long long ll;
    15 typedef pair <int,int> pii;
    16 int n,a,p,x;
    17 int main(void)
    18 {
    19     cin>>n;
    20     int maxn=0x3f3f3f3f;
    21     for(int i=0;i<n;++i)
    22     {
    23         cin>>a>>p>>x;
    24         if(x-a>0&&p<maxn)maxn=p;
    25     }
    26     if(maxn==0x3f3f3f3f)cout<<"-1"<<endl;
    27     else cout<<maxn<<endl;
    28     return 0;
    29 }

    C:

    题意:给定正整数N,从1到N共有多少个数不能表示为a的b次方。a和b都为不小于2的整数。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 #include <map>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <set>
    12 #include <cctype>
    13 using namespace std;
    14 typedef long long ll;
    15 typedef pair <int,int> pii;
    16 ll n,num;
    17 map<ll,int>mp;
    18 int main(void)
    19 {
    20     cin>>n;
    21     for(ll i=2;i*i<=n;++i)
    22     {
    23        ll k=i;
    24        while(k*i<=n)
    25        {
    26            k=k*i;
    27            if(!mp.count(k))
    28            {
    29                ++num;
    30                mp[k]++;
    31            }
    32        }
    33     }
    34     cout<<n-num<<endl;
    35     return 0;
    36 }

    D:

    题意:共有9*k张扑克牌,1到9每个数字k张,现在每人发五张,最后一张不知道数字,扑克牌的大小总和记为:,其中ci为该数字的张数。问第一个人赢的概率。

    分析:极致的暴力,极致的享受。模拟每种情况下是否能赢,然后通过组合数算下概率累加即可。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 #include <map>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <set>
    12 #include <cctype>
    13 using namespace std;
    14 typedef long long ll;
    15 typedef pair <int,int> pii;
    16 int k,cnt[10],p[6];
    17 ll sum;
    18 double ans;
    19 string s,t;
    20 int cal(string k)
    21 {
    22     int b[10]={0},res=0;
    23     for(int i=0;i<5;++i)b[k[i]-'0']++;
    24     for(int i=1;i<=9;++i)
    25     {
    26         res+=i*p[b[i]];
    27     }
    28     return res;
    29 }
    30 int main(void)
    31 {
    32     cin>>k;
    33     cin>>s>>t;
    34     for(int i=1;i<=9;++i)cnt[i]=k;
    35     for(int i=0;i<=5;++i)p[i]=pow(10,i);
    36     sum=9*k-8;
    37     for(int i=0;i<5;++i)
    38     {
    39         cnt[s[i]-'0']--;
    40         cnt[t[i]-'0']--;
    41     }
    42     for(int i=1;i<=9;++i)
    43     {
    44         for(int j=1;j<=9;++j)
    45         {
    46             if(i==j&&cnt[i]>1||i!=j&&cnt[i]>0&&cnt[j]>0)
    47             {
    48                 s[4]='0'+i;
    49                 t[4]='0'+j;
    50                 if(cal(s)>cal(t))
    51                 {
    52                     if(i==j)ans+=1.0*cnt[i]/sum*(cnt[i]-1)/(sum-1);
    53                     else ans+=1.0*cnt[i]/sum*cnt[j]/(sum-1);
    54                 }
    55             }
    56         }
    57     }
    58     cout<<ans<<endl;
    59     return 0;
    60 }

    E:

    题意:一辆火车从A和B来回,路上需要X秒,然后停留Y秒;现在从A出发,而主人公睡P秒,然后醒Q秒,如此反复,问是否存在某个时间使得主人公在醒着的时候在B点,若有输出最小的时间。

    分析:可以知道,假设存在这样的时间t,设r1=t%(2X+2Y),r2=t%(P+Q),那么有X<=r1<X+Y,P<=r2<P+Q,由于Y和Q较小,我们枚举所有的r1和r2,然后得到一个线性方程组,应用CRT求解即可。不了解CRT请移步:https://www.luogu.com.cn/problem/P4777

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 #include <map>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <set>
    12 #include <cctype>
    13 using namespace std;
    14 typedef long long ll;
    15 typedef pair <int,int> pii;
    16 int n=2;
    17 ll a1[10],b1[10];
    18 ll mul(ll a,ll b,ll mod)
    19 {
    20     ll res=0;
    21     while(b>0)
    22     {
    23         if(b&1)res=(res+a)%mod;
    24         a=(a+a)%mod;
    25         b>>=1;
    26     }
    27     return res;
    28 }
    29 ll exgcd(ll a,ll b,ll &x,ll &y)
    30 {
    31     if(b==0)
    32     {
    33         x=1;
    34         y=0;
    35         return a;
    36     }
    37     ll r=exgcd(b,a%b,x,y);
    38     ll t=x;
    39     x=y;
    40     y=t-a/b*y;
    41     return r;
    42 }
    43 ll excrt()
    44 {
    45     ll x,y;
    46     ll M=b1[1],ans=a1[1];
    47     for(int i=2;i<=n;++i)
    48     {
    49         ll a=M,b=b1[i],c=(a1[i]-ans%b+b)%b;
    50         ll r=exgcd(a,b,x,y),k=b/r;
    51         if(c%r!=0)return -1;
    52         x=mul(x,c/r,k);
    53         ans+=x*M;
    54         M*=k;
    55         ans=(ans%M+M)%M;
    56     }
    57     return (ans%M+M)%M;
    58 }
    59 int main(void)
    60 {
    61     int t;
    62     cin>>t;
    63     while(t--)
    64     {
    65         ll x,y,p,q;
    66         cin>>x>>y>>p>>q;
    67         ll ans=0;
    68         bool flag=false;
    69         for(ll i=x;i<x+y;++i)
    70         {
    71             for(ll j=p;j<p+q;++j)
    72             {
    73                 b1[1]=2*x+2*y;a1[1]=i;
    74                 b1[2]=p+q;a1[2]=j;
    75                 ll res=excrt();
    76                 if(res!=-1)
    77                 {
    78                     flag=true;
    79                     if(!ans)ans=res;
    80                     else ans=min(ans,res);
    81                 }
    82             }
    83         }
    84         if(!flag)cout<<"infinity"<<endl;
    85         else cout<<ans<<endl;
    86     }
    87     return 0;
    88 }

     F:

    网络流。暂时还不会QwQ。待补。

    终究独木难支。
  • 相关阅读:
    CF1539 VP 记录
    CF1529 VP 记录
    CF875C National Property 题解
    CF1545 比赛记录
    CF 1550 比赛记录
    CF1539E Game with Cards 题解
    CF1202F You Are Given Some Letters... 题解
    vmware Linux虚拟机挂载共享文件夹
    利用SOLR搭建企业搜索平台 之九(solr的查询语法)
    利用SOLR搭建企业搜索平台 之四(MultiCore)
  • 原文地址:https://www.cnblogs.com/yanying7/p/14457912.html
Copyright © 2011-2022 走看看