emm,一波掉分......难受
刚把d,f1补了,思路都是对的,敲的时候也挺顺的,但是比赛的时候就是怎么都想不出来。
所以还是敲代码太少,光有思路有屁用又A不了题......(打自己)
题目链接:https://codeforces.com/contest/1133
D.
题:暴力计算d的值然后统计。考虑两个wa点,一个是分情况讨论,a[i]==0且b[i]==0。另一个是卡精度(wa on pretest 37),要把d存成分数形式
code:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5+5;
ll a[maxn], b[maxn];
struct node{
ll fenzi, fenmu;
bool operator == (const node &oth) const {
if(fenzi == oth.fenzi && (oth.fenzi == 0 || fenmu == oth.fenmu)) return true;
else return false;
}
}d[maxn];
bool cmp(node x, node y){
return x.fenzi*y.fenmu < x.fenmu*y.fenzi;
}
int main(){
std::ios::sync_with_stdio(false);
int n;
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int j = 0; j < n; j++) cin >> b[j];
int ex = 0, cnt = 0;
for(int i = 0; i < n; i++){
if(a[i] == 0){
if(b[i] == 0) ex++;
}
else{
ll tmp = __gcd(a[i], b[i]);
d[cnt].fenzi = -b[i] / tmp;
d[cnt++].fenmu = a[i] / tmp;
}
}
sort(d, d+cnt, cmp);
int ans = 0, tmp = 0;
node pre = d[0];
for(int i = 0; i < cnt; i++){
if(pre == d[i]){
tmp++;
}
else{
ans = max(ans, tmp);
pre = d[i];
tmp = 1;
}
}
ans = max(ans, tmp);
ans += ex;
cout << ans << endl;
}
F1.
题解:直接找到度最大的点然后输出一棵树就可以了,bfs(作死的我还用kruskal......T7)
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
vector<int>G[maxn];
bool vis[maxn];
int main(){
int n, m;
cin >> n >> m;
int u, v;
while(m--){
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
int maxx = 0, maxid;
for(int i = 1; i <= n; i++){
if(G[i].size() > maxx){
maxx = G[i].size();
maxid = i;
}
}
memset(vis, 0, sizeof vis);
queue<int>q;
q.push(maxid);
vis[maxid] = true;
while(!q.empty()){
int cur = q.front(); q.pop();
for(int i = 0; i < G[cur].size(); i++){
int to = G[cur][i];
if(!vis[to]){
cout << cur << " " << to << endl;
q.push(to);
vis[to] = true;
}
}
}
}