Codeforces Round #219 (Div. 2)
B:
剛開始居然腦殘的一個一個加了。。。
思路:二分列舉長度,判斷是否費用超出w。
下面是程式碼:
#include<iostream>
using namespace std;
typedef long long LL;
const LL INF=1e17;
LL w,m,k;
LL cal(LL x)
{
if(x<10)
return x;
LL i=1,sum=0,bit=1;
for(;i*10<=x;i*=10,bit++)
{
sum+=bit*i*9;
}
LL digit=x/i%10;
sum+=(digit-1)*i*bit;
sum+=(x%i+1)*bit;
return sum;
}
int main()
{
cin>>w>>m>>k;
LL l=0,r=INF-m,mid,ans=0;
while(l<=r)
{
mid=(l+r)/2;
if(cal(m+mid-1)-cal(m-1)<=w/k)
{
ans=mid;
l=mid+1;
}
else r=mid-1;
}
cout<<ans<<endl;
return 0;
}
C:一個袋鼠可以裝下比他的1/2小的袋鼠,問最多還剩多少袋數在外面,一個袋鼠只能裝一個。
思路:先排序,然後雙指標遍歷。
下面是程式碼:
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=500000;
vector<int> a(500000);
int N;
int main()
{
cin>>N;
for(int i=1;i<=N;i++)
scanf("%d",&a[i]);
sort(a.begin()+1,a.begin()+N+1);
int i=1,j=N/2+1;
int ans=N;
while(i<=N/2&&j<=N)
{
if(a[j]>=a[i]*2)
{
ans--,j++,i++;
}
else j++;
}
cout<<ans<<endl;
return 0;
}
相關文章
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 948 (Div. 2)
- Codeforces Round 945 (Div. 2)
- Codeforces Round 873 (Div. 2)
- Codeforces Round 969 (Div. 2)
- Codeforces Round 949 (Div. 2)
- Codeforces Round 965 (Div. 2)
- Codeforces Round 963 (Div. 2)
- Codeforces Round 967 (Div. 2)