题目链接:https://cn.vjudge.net/contest/235654#overview
建队以来的第一场组队赛,打的总体来说一般。
赛后总结一下,前期打得不错,队友手速A掉两道水题。之后,就。。。
这次开的题其实挺多的,但可惜很多都没做出来。
想D题,一开始思路跑了。。。
E题,莫名其妙写挂了。。。
G题,debug了2小时,最后我们仨盯着电脑看了半个小时找出来了。。。
I题,窝想出了个O(n^2)的暴力算法,赛后查了一下,应该是对的(还没补)。可是由于前面卡的题有点多以及对自己字符串处理的不自信,写到一般没写完。。。
最后比赛结束,用Reply看了一下榜,RANK85,没能挤进银区,铜首。不过,这才是第一场,相信以后会越来越好的~
因此窝待补的题有:
G
E
I
D
好了,下面进入正题,看几道水题的题解(没更新完,最近要忙期末考试,不过会持续更新~)
--------------------------------------------------------------------------------------------------------------------------
J - Judging Moose
思路:C语言上机题
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a==0&&b==0)
printf("Not a moose\n");
else
{
if(a!=b)
printf("Odd %d\n",2*max(a,b));
else
printf("Even %d\n",a+b);
}
return 0;
}
B - Best Relay Team
思路:好像是简单排序。队友A的,赛后看了一下题解,应该不难。(这里就用队友的代码了)
#include<cstdio>
#include<algorithm>
#include<iostream>
#define maxn 505
using namespace std;
struct node
{
string name;
double t1,t2;
int num;
} p[maxn],tmp[maxn];
int max(int x,int y){
return x>y?x:y;
}
bool cmp(node a,node b){
return a.t2<b.t2;
}
int ansnum[5];
int main(){
int n;
scanf("%d",&n);
int k=-1;
double mint1=100.0;
for(int i=0;i<n;i++){
cin>>p[i].name>>p[i].t1>>p[i].t2;
p[i].num=tmp[i].num=i;
tmp[i].name=p[i].name;
tmp[i].t1=p[i].t1;
tmp[i].t2=p[i].t2;
}
double ans=100.0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
p[j].num=tmp[j].num;
p[j].name=tmp[j].name;
p[j].t1=tmp[j].t1;
p[j].t2=tmp[j].t2;
}
double t=0;
t+=p[i].t1;
sort(p,p+n,cmp);
int k=0;
for(int j=0;k<3;j++){
if(p[j].num!=i){
t+=p[j].t2;
k++;
}
}
if(ans>t){
ans=t;
ansnum[0]=i;
k=1;
for(int j=0;k<=4;j++){
if(p[j].num!=i){
ansnum[k]=p[j].num;
k++;
}
}
}
}
printf("%.2f\n",ans);
for(int i=0;i<4;i++){
for(int j=0;j<n;j++){
if(ansnum[i]==p[j].num)
cout<<p[j].name<<endl;
}
}
return 0;
}
G - Galactic Collegiate Programming Contest
思路:好像方法很多。队友用的是优先队列来模拟,重载比较运算符。标程给的是set,也是重载。看网上还有人用BIT做,真是神奇~
这个是队友写的优先队列的
#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int MAXN = 1e5+9;
int n, m;
bool in[MAXN];
struct node{
int id, a, b;
bool operator < (const node &y) const
{
return a==y.a?b<y.b:a>y.a;
}
}s[MAXN];
int main(){
priority_queue<node> Q;
scanf("%d%d", &n, &m);
for(int i=1; i<=n; ++i){
s[i].id=i;
}
int id, p;
while(m--){
scanf("%d%d", &id, &p);
s[id].a+=1;
s[id].b+=p;
if(1==id){
while(!Q.empty()){
node cur=Q.top();
if(s[1].a<cur.a||(s[1].a==cur.a&&s[1].b>cur.b)){
break;
}
else{
Q.pop();
in[cur.id]=false;
//printf("%d %d %d\n", s[1].a, s[2].a, s[3].a);
//printf("***%d %d\n", cur.a, s[cur.a].a);
if((s[cur.id].a>s[1].a||(s[cur.id].a==s[1].a&&s[cur.id].b<s[1].b))){
Q.push(s[cur.id]);
in[cur.id]=true;
}
}
}
}
else{
if(!in[id])
{
if(s[1].a<s[id].a||(s[1].a==s[id].a&&s[1].b>s[id].b))
{
Q.push(s[id]);
in[id]=true;
}
}
}
printf("%d\n", Q.size()+1);
}
return 0;
}
这个是我赛后补得set的
#include<bits/stdc++.h>
using namespace std;
bool vis[100010];
struct node
{
int x,y,z;
friend bool operator < (node a,node b)
{
if(a.x!=b.x)
{
return a.x<b.x;
}
else
{
if(a.y!=b.y)
return a.y>b.y;
else
{
return a.z>b.z;
}
}
}
node(){}
node(int x2,int y2,int z2)
{
x=x2;
y=y2;
z=z2;
}
} p[100010];
set<node> s;
int main()
{
int n,m;
int t1,t2;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
scanf("%d%d",&t1,&t2);
p[t1].x++;
p[t1].y+=t2;
if(t1==1)
{
while(!s.empty())
{
node tem=*s.begin();
if((tem.x>p[1].x)||(tem.x==p[1].x&&tem.y<p[1].y))
break;
s.erase(s.begin());
}
}
else
{
s.erase(node(p[t1].x-1,p[t1].y-t2,t1));
if((p[t1].x>p[1].x)||(p[t1].x==p[1].x&&p[t1].y<p[1].y))
s.insert(node(p[t1].x,p[t1].y,t1));
}
printf("%d\n",s.size()+1);
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------
(先写到这,待更,预习期末考试去了~)