Codeforces Round #610 (Div. 2)
作者:互联网
题库链接
https://codeforces.com/contest/1282
A. Temporarily unavailable
x轴,三个点a,b,c,在c处有一个半径为r的圈,求[a,b]段不在圈内的点的个数
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 200100;
const int M = 1e9+7;
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
#endif
int t;
cin>>t;
while(t--)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a > b) swap(a,b);
int l = c-d;
int r = c+d;
int ans = 0;
if(r < a || l > b)
{
cout<<b-a<<endl;
continue;
}
if(l > a) ans += l-a;
if(r < b) ans += b-r;
cout<<ans<<endl;
}
return 0;
}
B. K for the Price of One
n个物品,买k个物品只需要花k个里面的最贵的那个的钱就行了(可以使用无数次,有没有被坑到了的),p块钱最多可以买多少个物品?
按价格排个序,然后就按k求出k个序列
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 210000;
const int M = 1e9+7;
ll a[maxn];
ll b[maxn];
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
#endif
int n,k,t;
ll p;
cin>>t;
while(t--)
{
cin>>n>>p>>k;
mem(a,0);mem(b,0);
for(int i = 1; i <= n; i++)
{
cin>>a[i];
}
sort(a+1,a+n+1);
ll res = 0,ans = 0;
for(int i = 1; i < k; i++)
{
b[i] = b[i-1]+a[i];
if(b[i] <= p) ans = i;
}
for(int i = 0; i < k; i++)
{
for(int j = i+k; j <= n; j+=k)
{
b[i] += a[j];
//cout<<b[i]<<endl;
if(b[i] <= p && j > ans) ans = j;
}
}
cout<<ans<<endl;
}
return 0;
}
C. Petya and Exam
参加考试,0代表容易题,解出需要a分钟,1代表难题,解出需要b分钟,可以从任意时间s退出考试,n个题目,每个题目有个限制时间ti,如果要从s时间退出考试则必须把ti<=s的全部题目做完,求最多可以做几个题目;
贪心,先对t排序,当做完i题,总时间小于\(t_{i+1}-1\),是合法的,并且可以在多余的时间里面多做一些简单题
会爆int
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 200100;
const int M = 1e9+7;
int n,m,k,t,x,y;
ll sum[maxn];
struct node
{
ll ty,t;
}a[maxn];
bool cmp(node a,node b)
{
return a.t < b.t;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
#endif
cin(t);
while(t--)
{
cin(n);cin(m);cin(x);cin(y);
for(int i = 0; i < n; i++)
{
cin>>a[i].ty;
}
for(int i = 0; i < n; i++)
{
cin>>a[i].t;
}
sort(a,a+n,cmp);
a[n].t = m+1;
ll time = 0;
int res = 0;
for(int i = n-1; i >= 0; i--)
{
sum[i] = res;
if(a[i].ty == 0) res++;
}
int ans = 0;
if(a[0].t) ans = min((a[0].t-1)/x,sum[0]); //在t[0]前面做题
res = 0;
for(int i = 0; i < n; i++)
{
if(a[i].ty == 0) time += x;
else time += y;
if(time < a[i+1].t)
{
res = i+1;
res += min((a[i+1].t-time-1)/x,sum[i]);
ans = max(ans,res);
}
}
cout<<ans<<endl;
}
return 0;
}
标签:const,int,610,cin,Codeforces,ans,Div,ll,define 来源: https://www.cnblogs.com/hezongdnf/p/12095494.html