哎呀,好久沒有更新博客啦,今天又刷了一波BC,而且又漲分,還是蠻開心的。
近來很多人告知了我的不足,我也漸漸體會到自己小題做的越來越好了,但是大題還是沒有思路。
肯定是我光刷小題,不去學算法,大題也做的不多,結果纔會這樣。
雖說學算法是個日積月累的過程,但我看我要抓緊步伐,開始一些比較難一點的算法的學習了。
HDU-5499 SDOI
看不懂英文的同學去Bestcoder裏面看中文版把(我估計英文版做出來是夠嗆的)
思路:這道題目不是特別難,但是特別煩,假設這不是一道中文題,讓我用英文來看的話,我不知道自己還能不能很快做出來,甚至能不能做出來。我的話比較習慣用結構體排序。先讀取數據,將兩次最高的分數保存,如果遇到女性用flag記錄。然後再計算一遍每個人的最終分數,排序!最後就是將最佳女選手挑出,如果flag記錄了,那麼就從前往後查找第一個女性選手。如果她在前m個,那麼就不用移動;但是如果她不在前m個,那麼就將她與第m個選手交換位置。輸出答案!
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100+5
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
struct man
{
char name[25];
int sex,r1,r2;
double r;
friend bool operator < (const man& A,const man& B)
{
return A.r > B.r;
}
}a[maxn];
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
int flag=0,ma1=0,ma2=0;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
{
char k[10];
scanf("%s %s %d %d",a[i].name,k,&a[i].r1,&a[i].r2);
ma1=max(ma1,a[i].r1);
ma2=max(ma2,a[i].r2);
if(k[0]=='m')a[i].sex=1;
else a[i].sex=0,flag=1;
}
for(int i=0;i<n;i++)
a[i].r=(1.0*a[i].r1/ma1)*300*0.3+(1.0*a[i].r2/ma2)*300*0.7;
sort(a,a+n);
if(flag)
{
for(int i=0;i<n;i++)
{
if(!a[i].sex)
{
if(i+1>m)
{
swap(a[i],a[m-1]);
}
break;
}
}
}
puts("The member list of Shandong team is as follows:");
for(int i=0;i<m;i++)
printf("%s\n",a[i].name);
}
return 0;
}
HDU- 5500 Reorder the Books
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100+5
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
int a[30];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",a+i);
int k=n;
for(int i=n;i>=1;i--)
if(a[i]==k)k--;
printf("%d\n",k);
}
return 0;
}