D:没有注意到a==0&&b==0的情况,把自己卡崩了。对于数学公式推导一定要注意关于0的特殊情况,不可以少
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,,-};
const int dy[]={,-,,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+;
struct node
{
int a,b;
long double c;
}d[MAXN]; bool cmp(node a,node b)
{
return abs(a.a)<abs(b.a);
} bool cmp2(node a,node b)
{
return a.c<b.c;
} int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&d[i].a);
}
for(int i=;i<=n;i++)
{
scanf("%d",&d[i].b);
}
int cnts=;
for(int i=;i<=n;i++)
{
if(d[i].a==&&d[i].b==) cnts++; if(d[i].a!=)
d[i].c=d[i].b*1.0/d[i].a;
else d[i].c=;
}
sort(d+,d+n+,cmp);
int t=;
for(int i=;i<=n;i++)
{
if(d[i].a==) continue;
else
{
t=i;
break;
}
}
if(d[n].a==)
{
cout << cnts<<endl;
return ;
}
// cout <<t<<endl;
/* for(int i=t;i<=n;i++)
{
cout <<d[i].c<<" ";
}*/
sort(d+t,d+n+,cmp2);
/*for(int i=t;i<=n;i++)
{
cout <<d[i].c<<" ";
}*/
int ans=;int cnt=;long double x=d[t].c;
for(int i=t+;i<=n;i++)
{
if(d[i].c==x)
{
cnt++;
ans=max(ans,cnt);
}
else
{
x=d[i].c;
cnt=;
}
}
cout <<ans+cnts<<endl;
return ;
}
F1:被D心态搞崩,然后F1比赛的时候读不懂题,Your task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible这句话半天理解不了,下来问,才知道直接简单bfs就可以了,然后忘了bfs咋写,写了好长时间(太菜了)
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,,-};
const int dy[]={,-,,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+;
int dis[MAXN];
vector <int> G[MAXN]; void bfs(int M)
{
queue <int> Q;
Q.push(M);
dis[M]=;
while(!Q.empty())
{
int F=Q.front();Q.pop(); for(int i=;i<G[F].size();i++)
{
if(dis[G[F][i]]==)
{
printf("%d %d\n",F,G[F][i]);
Q.push(G[F][i]);
dis[G[F][i]]=;
}
}
}
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int a,b;scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
int Msize=;int M=;
for(int i=;i<=n;i++)
{
if(G[i].size()>Msize)
{
Msize=G[i].size();
M=i;
}
}
bfs(M);
return ;
}
现在还是一碰见图和树的问题就发怵。
E:还没写出来