生活随笔
收集整理的這篇文章主要介紹了
Acwing第 27 场周赛【完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 4079. 數字串【簽到】
- 4080. 第k個數【思維 / 二分】
- 4081. 選數【費用背包】
4079. 數字串【簽到】
https://www.acwing.com/problem/content/4082/
#include<bits/stdc++.h>
using namespace std
;
int main(void)
{string s
;for(int i
=1;i
<=500;i
++) s
+=to_string(i
);int t
; cin
>>t
;while(t
--){int n
; cin
>>n
;cout
<<s
[n
-1]<<endl
;}return 0;
}
4080. 第k個數【思維 / 二分】
https://www.acwing.com/problem/content/description/4083/
#include<bits/stdc++.h>
using namespace std
;
typedef long long int LL
;
LL n
,m
,k
;
bool check(LL mid
)
{LL sum
=0;for(int i
=1;i
<=n
;i
++) sum
+=min(m
,mid
/i
);return sum
>=k
;
}
int main(void)
{cin
>>n
>>m
>>k
;LL l
=1,r
=n
*m
;while(l
<r
){LL mid
=l
+r
>>1;if(check(mid
)) r
=mid
;else l
=mid
+1;}cout
<<l
<<endl
;return 0;
}
4081. 選數【費用背包】
https://www.acwing.com/problem/content/description/4084/
#include<bits/stdc++.h>
using namespace std
;
typedef long long int LL
;
const int N
=210,M
=5010;
int n
,m
;
int v
[N
],w
[N
];
int f
[N
][M
];
int main(void)
{cin
>>n
>>m
;for(int i
=1;i
<=n
;i
++){LL x
; cin
>>x
;while(x
%5==0) x
/=5,v
[i
]++;while(x
%2==0) x
/=2,w
[i
]++;}memset(f
,-0x3f,sizeof f
);f
[0][0]=0;for(int i
=1;i
<=n
;i
++)for(int j
=m
;j
;j
--)for(int k
=i
*25;k
>=v
[i
];k
--){f
[j
][k
]=max(f
[j
][k
],f
[j
-1][k
-v
[i
]]+w
[i
]);}int res
=0;for(int i
=1;i
<M
;i
++) res
=max(res
,min(i
,f
[m
][i
]));cout
<<res
;return 0;
}
總結
以上是生活随笔為你收集整理的Acwing第 27 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。