贪心
C
#include <bits/stdc++.h>
using namespace std;
struct node
{
double left,right;
}jk[10101];
bool cmp(node x,node y)
{
return x.left <y.left;
}
int main()
{
int n,flag=0,sum,k=1;
double x,y,d,p;
while(cin >>n >> d&&(n||d))
{
flag=1;
for(int i=0;i<n;i++)
{
cin >> x >> y;
if(d<y)
{
flag=0;
continue;
}
jk[i].left=x-sqrt(d*d-y*y);
jk[i].right=x+sqrt(d*d-y*y);
}
if(flag)
{
sort(jk,jk+n,cmp);
sum=1,p=jk[0].right;
for(int i =1;i<n;i++ )
{
if(jk[i].left>p)
{
sum++;
p=jk[i].right;
}
else if(jk[i].right<p)
{
p=jk[i].right;
}
}
cout<<"Case "<<k++<<": "<<sum<<endl;
}
else
{
cout<<"Case "<<k++<<": "<<"-1"<<endl;
}
}
return 0;
}
D
#include <bits/stdc++.h>
using namespace std;
int a[1010],b[1010];
int main()
{
int n;
while(cin >> n&&n)
{
for(int i=0;i<n;i++)
{
cin >> a[i]; //田忌
}
for(int i=0;i<n;i++)
{
cin >> b[i]; //齐王
}
sort(a,a+n);
sort(b,b+n);
int sum=0;
int l1=0,l2=0; //头指针
int r1=n-1,r2=n-1; //尾指针
while(l1<=r1)
{
if(a[r1]>b[r2])
{
r1--;
r2--;
sum+=200;
}
else if(a[r1]<b[r2])
{
l1++;
r2--;
sum-=200;
}
else
{
if(a[l1]>b[l2])
{
sum+=200;
l1++;
l2++;
}
else
{
if(a[l1]<b[r2])
{
sum-=200;
}
l1++;
r2--;
}
}
}
cout << sum << endl;
}
}
E
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct node
{
int f,d,id;
}jk[10101];
int n,t,ans;
int dis[1000],best[1000],temp[1000];
priority_queue<node>q;
bool operator < ( const node &a,const node &b)
{
if(a.f==b.f) return a.id>b.id;
else return a.f<b.f;
}
int main()
{
int n,now;
while(cin >> n&&n)
{
cin >> t;
t*=12;
for(int i=0;i<n;i++)
{
cin >> jk[i].f;
}
for(int i=0;i<n;i++)
{
cin >> jk[i].d;
jk[i].id=i;
best[i]=0;
}
dis[0]=0;
for(int i=1;i<n;i++)
{
cin >> dis[i];
dis[i]+=dis[i-1];
}
ans=-1;
for(int i=0;i<n;i++)
{
now=0;
while(!q.empty())
{
q.pop();
}
for(int j=0;j<=i;j++)
{
q.push(jk[j]);
}
for(int j=0;j<n;j++)
{
temp[j]=0;
}
int tt=t-dis[i];
while(tt>0)
{
node k = q.top();
q.pop();
tt--;
now+=k.f;
temp[k.id]++;
k.f-=k.d;
if(k.f<0) k.f=0;
q.push(k);
}
if(now>ans)
{
ans=now;
for(int j=0;j<n;j++)
{
best[j]=temp[j];
}
}
}
for(int i=0;i<n-1;i++)
{
cout << best[i]*5 << ", ";
}
cout << best[n-1]*5 << endl;
cout << "Number of fish expected: " << ans << endl;
cout << endl;
}
return 0;
}
F
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include<cstring>
#define MAXN 110
using namespace std;
struct node
{
int a,b;
double c;
}jk[10101];
double totw, totv;
bool operator < (const node &a, const node &b)
{
return a.c > b.c;
}
int main()
{
int t,n,k;
cin >> t;
while(t--)
{
memset(jk,0,sizeof(jk));
cin >> k >> n;
for(int i=1;i<=n;i++)
{
cin >> jk[i].b >> jk[i].a;
jk[i].c=(1.0*jk[i].a)/jk[i].b;
}
sort(jk+1,jk+n+1);
double sum=0.0;
double num=0.0;
for(int i=1;i<=n;i++)
{
if(num+jk[i].b<=k)
{
sum+=jk[i].a;
num+=jk[i].b;
}
else
{
sum+=jk[i].c*(k-num);
num=k;
break;
}
}
printf("%.02lf\n",sum);
}
}
G(现在超时,待改)
H
#include<iostream>
#include<algorithm>
using namespace std;
int h[20001],n,s;
int main()
{
cin>>n>>s;
for(int i=0;i<n;i++)
cin>>h[i];
sort(h,h+n);
for(int i=n-1;i>=0;i--)
{
s-=h[i];
if(s<=0)
{
cout<<n-i;
return 0;
}
}
}
I
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 10 + 1;
char s[N];
int main()
{
int t, k;
scanf("%d", &t);
while(t--)
{
scanf("%s%d", s, &k);
int len = strlen(s);
while(k--)
{
for(int i = 0; i < len; i++)
if(s[i] > s[i + 1])
{
for(int j = i; j < len; j++) s[j] = s[j + 1];
break;
}
len--;
}
printf("%s\n", s);
}
return 0;
}
J
#include <iostream>
#include <algorithm>
using namespace std;
int n,l1,l2,r1,r2;
int c[1009],s[1009];
int fun(int *a,int *b)
{
int ans=0;
int l1=l2=0;
int r1=r2=n-1;
while(l1<=r1&&l2<=r2)
{
if(a[r1]<b[r2])
{
ans++;
l1++;
r2--;
}
else if(a[r1]>b[r2])
{
ans+=3;
r1--;
r2--;
}
else
{
if(a[l1]<b[l2])
{
ans++;
l1++;
r2--;
}
else if(a[l1]>b[l2])
{
ans+=3;
l1++;
l2++;
}
else
{
if(a[l1]==b[r2])
{
ans+=2;
}
else
{
ans++;
}
l1++;
r2--;
}
}
}
return ans;
}
int main()
{
int mm,mi;
while(cin >> n&&n)
{
for(int i=0;i<n;i++)
{
cin >> c[i];
}
for(int i=0;i<n;i++)
{
cin >> s[i];
}
sort(c,c+n);
sort(s,s+n);
mm=fun(s,c);
mi=4*n-fun(c,s);
cout << mm << " " << mi << endl;
}
return 0;
}