标签:
虽然是sb题,,但是要注意h可能<=a,,,开始忘记判了WA得很开心。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 long long h, a, b, k; 8 int main(){ 9 int tt = 0; 10 while(scanf("%lld%lld%lld%lld", &h, &a, &b, &k) && h){ 11 printf("Case #%d: ", ++ tt); 12 if(a >= h || h+b*(k-1)-a*k < 1){puts("YES"); continue;} 13 if(b*(k+1)-a*k < 0){puts("YES"); continue;} 14 puts("NO"); 15 } 16 return 0; 17 }
签到水题,,按斜率排下序然后扫一遍就好了
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #define MAXN 100005 5 using namespace std; 6 int n, a[MAXN], E[MAXN], K[MAXN]; 7 bool cmp(int a, int b){return (E[a]*K[b]) <= (E[b]*K[a]);} 8 long long ans, tt; 9 int main(){ 10 scanf("%d", &n); 11 for(int i = 1; i <= n; i ++) scanf("%d", &E[i]); 12 for(int i = 1; i <= n; i ++) scanf("%d", &K[i]), a[i] = i; 13 sort(a + 1, a + n + 1, cmp); 14 for(int i = 1; i <= n; i ++){ 15 tt += E[a[i]]; ans += K[a[i]] * tt; 16 } 17 cout << ans << endl; 18 return 0; 19 }
标签:
原文地址:http://www.cnblogs.com/lixintong911/p/4980847.html