1 #include <iomanip> 2 #include <iostream> 3 #include <cstdio> 4 #include <cmath> 5 #include <cstring> 6 #include <algorithm> 7 #include <queue> 8 #include <stack> 9 #include <vector> 10 #include <map> 11 using namespace std; 12 const int nmax=200200; 13 int main(int argc, char *argv[]) 14 { 15 int n,a[nmax]; 16 long long t; 17 scanf("%d%I64d",&n,&t); 18 int mi=1e9+10; 19 for(int i=1;i<=n;i++) 20 { 21 scanf("%d",&a[i]); 22 if(a[i]>t) 23 { 24 i--; 25 n--; 26 } 27 if(a[i]<mi) 28 mi=a[i]; 29 } 30 long long sum=0; 31 long long l=1; 32 while(1) 33 { 34 if(l==1) 35 { 36 long long sum1=0,x=0; 37 for(int i=1;i<=n;i++) 38 { 39 if(t>=a[i]) 40 sum1+=a[i],x++; 41 } 42 if(sum1==0) 43 break; 44 sum+=(t/sum1*x); 45 t-=(t/sum1*sum1); 46 } 47 if(t<mi) 48 break; 49 if(a[l]<=t) 50 t-=a[l],sum++; 51 l++; 52 if(l==n+1) 53 l=1; 54 } 55 printf("%I64d\n",sum); 56 return 0; 57 } 58
1 #include <iomanip> 2 #include <iostream> 3 #include <cstdio> 4 #include <cmath> 5 #include <cstring> 6 #include <algorithm> 7 #include <queue> 8 #include <stack> 9 #include <vector> 10 #include <map> 11 using namespace std; 12 const int nmax=200200; 13 int main(int argc, char *argv[]) 14 { 15 int n,a[nmax]; 16 long long t; 17 scanf("%d%I64d",&n,&t); 18 for(int i=1;i<=n;i++) 19 scanf("%d",&a[i]); 20 long long s,sum=0; 21 int x=0; 22 while(1) 23 { 24 for(int i=1;i<=n;i++) 25 if(s+a[i]<=t) 26 s+=a[i],x++; 27 if(s==0) 28 break; 29 sum+=t/s*x,t%=s; 30 s=0,x=0; 31 } 32 printf("%I64d\n",sum); 33 return 0; 34 } 35
原文地址:https://www.cnblogs.com/huluxin/p/9886414.html
时间: 2024-10-10 04:44:41