Problem E. Evaluations Gym - 101840E 很留皮的题
2020-08-25 20:14
1451 查看
这是我的代码和我的搭档的代码的结合体,当然自己的代码根本不对(理解问题,product是乘积),但是搭档改对了
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <algorithm> #include <math.h> #include <stack> #include <queue> #include <set> #include <map> #include <vector> #include <utility> #define Fast_io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define filein freopen("evaluations.in", "r", stdin); #define fileout freopen("output.txt", "w", stdout); using namespace std; typedef long long ll; const int N = 1e5 + 10; struct node { int w; int data, next; } e[100005]; int head[100005], cnt; int numm[N], vis[N]; void creat() { for (int i = 2; i < N; i++) { if (!vis[i]) { vis[i] = 1; numm[i]++; for (int j = 2 * i; j < N; j += i) { vis[j] = 1; numm[j]++; } } } }numm记录的是素数的个数,并且这些素数是不想同的,当时埃氏筛的时候应该想到这一点。 void add(int u, int v, int w) { e[cnt].w = w; e[cnt].data = v; e[cnt].next = head[u]; head[u] = cnt++; } bool book[100005]; ll t; ll dfs(int u, int pre, int sum) { int ans = 0; int i; for (i = head[u]; i != -1; i = e[i].next) { if (e[i].data == pre) continue; book[e[i].data] = 1; if (sum + e[i].w <= 2) 还必须在找素数直到正好有两个。 { ans += dfs(e[i].data, u, sum + e[i].w); } } if (sum == 2)///正好有两个 ans++; return ans; } int main() { Fast_io; // filein; int tt, m = 1; cin >> tt; creat(); int i; for (i = 0; i < 100; i++) printf("%d ", numm[i]); while (tt--) { int n; cin >> n; memset(head, -1, sizeof(head)); int i; t = 0; for (i = 0; i < n - 1; i++) { int x, y, w; cin >> x >> y >> w; add(x, y, numm[w]); add(y, x, numm[w]); } for (i = 1; i <= n; i++) { memset(book, 0, sizeof book); book[i] = 1; t += dfs(i, 0, 0); // printf("%d\n", t); } printf("Case %d: %lld\n", m++, t / 2);//无向图,多找了一倍 } return 0; }
忽忽悠悠的明白了,当时还想把每条边直接乘,然后再找出两个不等的素数,可是复杂度太高,而且实现麻烦,哎!!多理解把!!!!!!!!!
相关文章推荐
- 【模拟】NEERC15 E Easy Problemset (Codeforces GYM 100851)
- 【Gym 100685J】Just Another Disney Problem(交互/排序)
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- Gym 100685 J Just Another Disney Problem 趣题,稳定排序
- gym 101124 Problem E. Dance Party(概率)
- Problem B. Black and White Gym-100801B] 想象力
- Codeforces Gym 100623D Problem D. Deposits
- Round B APAC Test 2017 Problem B. Sherlock and Watson Gym Secrets
- Problem B. Sherlock and Watson Gym Secrets Google APAC 2017 University Test Round B
- JDI thread evaluations' has encountered a problem
- Problem D. Dales and Hills - Gym - 101411D 【动态规划经典题 - 思维】
- HDU Problem 5395 Gym Class 【拓扑排序+优先队列】
- codeforce gym 101726 problem D Poker
- Gym 100646 Problem E: Su-Su-Sudoku 水题
- codeforce gym 101726 problem C Ekaterinburg Pyramids
- Gym 100646 Problem C: LCR 模拟题
- 'JDI thread evaluations' has encountered a problem
- codeforce gym 101726 problem B. Spy Duel
- PROBLEM_J: Gym 100345J - Zen Garden
- Codeforces Gym 100610 Problem E. Explicit Formula 水题