寒假第四周 2.1 --- 2.7

2.1 --- 2.3

 

2.4

 cf 535 c Tavas and Karafs

wa 得好酸爽T_T,后来把二分的lb,ub,mid 的类型改成 int 就过了,不知道为什么

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 typedef long long LL;
 8 int n,A,B;
 9 const int maxn = 1e5+5;
10 const int INF = (1<<30)-1;
11 int l[maxn],t[maxn],m[maxn];
12 
13 int ok(int l,int r,int id){
14     LL x = 1LL*A + 1LL*(l-1)*B;
15     LL y = 1LL*A + 1LL*(r-1)*B;
16     LL sum = 1LL*(x+y)*(r-l+1)/2;
17     //printf("---id = %d sum = %I64d\n",id,sum);
18     return 1LL*m[id]*t[id] >= sum && y <= t[id];
19 }
20 
21 void solve(){
22     int lb,ub,mid;
23     int flag;
24     for(int i = 1;i <= n;i++){
25         lb = l[i];ub = 1e6,flag = 0;
26         int ans = 0;
27         for(int k = 0;k <= 100;k++){
28             mid = lb + (ub-lb)/2;
29             if(ok(l[i],mid,i)){
30                 flag = 1;
31                 lb = mid+1;
32                 ans = max(ans,mid);
33             }
34             else ub = mid-1;
35            // printf("i = %d lb = %I64d ub = %I64d mid = %I64d\n",i,lb,ub,mid);
36         }
37         if(flag && ans >= l[i]) printf("%d\n",ans);
38         else puts("-1");
39     }
40 }
41 
42 int main(){
43     while(scanf("%d %d %d",&A,&B,&n) != EOF){
44         for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
45         solve();
46     }
47     return 0;
48 }
View Code

 cf 534 c C - Polycarpus' Dice

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 typedef long long LL;
 8 const int maxn = 5e6+5;
 9 int d[maxn],ans[maxn];
10 int n;
11 LL A,sum;
12 
13 void solve(){
14     LL leftsum = 0,minn,maxx;
15     for(int i = 1;i <= n;i++){
16         leftsum = sum-d[i];
17         if(A - leftsum > 0) minn = A-leftsum;
18         else minn = 1;
19         maxx = min(1LL*d[i],A-(n-1));
20 
21       //  printf("leftsum = %I64d minn = %I64d  maxx = %I64d\n",leftsum,minn,maxx);
22 
23         if(minn > maxx) printf("%d ",d[i]-1);
24         else printf("%d ",d[i]-(maxx-minn+1));
25     }
26     printf("\n");
27 }
28 
29 int main(){
30     while(scanf("%d %I64d",&n,&A) != EOF){
31         sum = 0;
32         for(int i = 1;i <= n;i++) scanf("%d",&d[i]),sum += 1LL*d[i];
33         solve();
34     }
35     return 0;
36 }
View Code

 

你可能感兴趣的:(寒假第四周 2.1 --- 2.7)