structmooncake{ double store; //库存量 double sell; //总售价 double price; //单价 }cake[1010]; boolcmp(mooncake a, mooncake b){ return a.price > b.price; } intmain(){ int n; double d; scanf("%d %lf", &n, &d); int i; for (i = 0; i < n; i++) scanf("%lf", &cake[i].store); for (i = 0; i < n; i++) scanf("%lf", &cake[i].sell); for (i = 0; i < n; i++) cake[i].price = cake[i].sell / cake[i].store; sort(cake, cake + n, cmp); //按单价排序 double ans = 0; //收益 for (i = 0; i < n; i++){ if (cake[i].store <= d){ d -= cake[i].store; ans += cake[i].sell; } else{ ans += cake[i].price * d; d = 0; } } printf("%.2f", ans); }
intmain(){ int i; int a[10]; for (i = 0; i < 10; i++) scanf("%d", &a[i]); for (i = 1; i < 10; i++) if (a[i] > 0){ printf("%d", i); a[i]--; break; } for (i = 0; i < 10; i++) while (a[i] > 0){ printf("%d", i); a[i]--; } }
constint maxn = 110; structInteval{ int x; int y; } I[maxn]; //排序比较函数,先按左端点从大到小排序,相同则按右端点从小到大排序 boolcmp(struct Inteval a, struct Inteval b){ if (a.x != b.x) return a.x > b.x; elsereturn a.y < b.y; } intmain(){ int i; int n; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d %d", &I[i].x, &I[i].y); sort( I, I + n, cmp); //对区间进行排序 for (i = 0; i < n; i++){ printf("%d %d\n", I[i].x, I[i].y); } int num = 1; //不相交区间个数,首先选中了I[0] int lastx = I[0].x; //记录上一个被选中区间的左端点 for (i = 1; i < n; i++){ if (I[i].y <= lastx){ //如果该区间的右端点在 lastx 的左边 lastx = I[i].x; num++; } } printf("%d\n", num); }