请求c语言大佬用c帮忙编个程200

zouchengwoerzi |浏览1263次
收藏|2021/06/16 21:05

满意回答

2021/06/16 21:14

C的程序参考#include <stdio.h>long long a[123456];long long mmin(long long x,long long y) { return (x<y)?x:y;}int main(){ int n,i; long long sum; long long res = 0; scanf("%d%I64d",&n,&sum); for( i = 0;i < n;i++) scanf("%I64d",&a[i]); for(i = 1;i < n;i++) a[i] = mmin(a[i],a[i-1] * 2); for(i = n-2;i >= 0;i--) a[i] = mmin(a[i],a[i+1]); for(i = n;i < 31;i++) a[i] = a[i-1] << 1; for(i = 0;i < 31;i++) { if(res > a[i]) res = a[i]; if(sum & (1 << i) ) res += a[i]; } printf("%I64d\n",res); return 0;}注意,编译器要支持64位,如gcc

whoami1978

其他回答(0)
0人关注该问题
+1

 加载中...