zoukankan      html  css  js  c++  java
  • 【CF1073D】Berland Fair(模拟)

    题意:初始有t元,每次从1开始买,从1到n依次有n个人,每个人的东西价格为a[i],该人依次能买就买,到n之后再回到1从头开始,问最后能买到的东西数量

    n<=2e5,t<=1e18,a[i]<=1e9

    思路:显然购买是有周期的,每次周期变化都会少至少一个人,所以至多进行n次周期的变化

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N  200010
    21 #define M  200
    22 #define MOD 998244353
    23 #define eps 1e-8 
    24 #define pi acos(-1)
    25 #define oo 1000000000
    26 
    27 ll a[N];
    28 
    29 int main()
    30 {
    31     //freopen("D.in","r",stdin);
    32     //freopen("D.out","w",stdout);
    33     int n;
    34     ll t;
    35     scanf("%d%lld",&n,&t);
    36     ll mn=oo;
    37     for(int i=1;i<=n;i++) 
    38     {
    39         scanf("%lld",&a[i]);
    40         mn=min(mn,a[i]);
    41     }
    42 
    43     ll ans=0;
    44     while(t>=mn)
    45     {
    46         ll s=0;
    47         ll k=0;
    48         for(int i=1;i<=n;i++) 
    49          if(t>=a[i])
    50          {
    51              t-=a[i];
    52              s++;
    53              k+=a[i];
    54          }
    55         ans+=s+t/k*s;
    56         t%=k;
    57     }
    58     printf("%lld
    ",ans);
    59      return 0;
    60 }
  • 相关阅读:
    MYSQL 优化(二),持续更新收藏
    一些linux命令 备份下
    lsyncd +xinetd+syncd 多服务器文件同步
    阿里slb+ecs+https
    微擎 从 php5 到php7 的各种填坑 持续更新
    lmap
    微擎的ifp ife ifpp
    工具索引 mark名字
    Funny Bug || Sky Hole
    mysql 查询小技巧
  • 原文地址:https://www.cnblogs.com/myx12345/p/9858179.html
Copyright © 2011-2022 走看看