牛客IOI周賽22 普及組

2022-06-30 07:27:09 字數 2313 閱讀 4342

a. 戰爭尾聲

思路:列舉從(1, 1)至(200,200)所有的點,判斷是否存在乙個點到其他所有點距離均相等,然而這道題實際上不一定要開double 用int一樣可以過,因為在計算距離的時候保留距離的平方值進行比較也是可以允許的,時間複雜度:o(n * 200^2).

100分**:

#include#include#define debug(x) cout << "***" << x << endl

const int n = 205;

const double eps = 1e-4;

using namespace std;

int n, cnt = 0, flag = 1;

struct node

a[n];

int main()

}if(flag)

}if(flag) break;

}if(!flag) cout << "war is cruel." << endl;

return 0;

}

b. 簽訂協議

思路:60分**:

#include#include#include#define debug(x) cout << "***" << x << endl

using namespace std;

typedef pairpii;

const int n = 8e5 + 5;

int n;

vectora;

priority_queue, less> heap;

int main()

); heap.push();

}int num = 0;

while(heap.size())

//debug(val);}}

cout << num <100分**:

#include#includeusing namespace std;

const int n = 8e5 + 5;

int n;

struct node

a[n];

bool cmp(node a, node b)

int main()

sort(a + 1, a + 1 + n, cmp);

int cnt = 0;

for(int i = 1; i <= n - 1; i++)

cout << cnt + 1;

return 0;

}

c. (暫時懵逼)

d. 路線規劃

思路:最小生成數的權值 * 2即為答案,權值需要開ll,不然只能過60%

prime**:

#include#include#include#includeusing namespace std;

typedef long long ll;

typedef pairpii;

const int n = 2e5 + 5;

int n, m;

int dis[n], st[n];

vectorg[n];

priority_queue, greater> heap;

ll prime()

); //權值、頂點

while(heap.size() && cnt < n));}

}}

return sum;

}int main()

); g[v].push_back();

}cout << prime() * 2 << endl;

return 0;

}

kruaskal**:

#include#include#define debug(x) cout << "***" << x << endl

using namespace std;

typedef long long ll;

const int n = 2e6 + 5;

const int m = 2e5 + 5;

ll par[m];

int n, m;

struct edge

e[n];

bool cmp(edge x, edge y)

ll find(ll x)

void merge(ll x, ll y)

ll kruskal()

if(cnt == n - 1) break;

}return sum;

}int main()

牛客IOI周賽22 普及組

1.戰爭尾聲 題目鏈結 題解 因為資料量非常小,直接遍歷每乙個點即可 include include include using namespace std typedef pair int,int pii double getlength double x,double y,pii v intma...

牛客IOI周賽22 普及組

暴力列舉 author sunlakewalk include include include include include include include include include include include include include include include includ...

牛客IOI周賽20 普及組

牛客的簽到題,最暴力的做法就是把數每個因子羅列出來,但是這樣只有60的暴力分,我們從題目的資料可以看到 資料範圍是1e7的,在學習素數的時候我們知道乙個因子就能推出另乙個因子,所以我們沒必要從1判斷到n 1 直接i i n就能找到所有的因子,但是注意像16這樣的數,當我們的i為4的時候,這個4的因子...