2016 ICPC 大连 网络赛

来源:互联网 发布:java讲师技术含量 编辑:程序博客网 时间:2024/04/28 20:00

5873
http://acm.hdu.edu.cn/showproblem.php?pid=5873

最难在读题。。注意是t组数据 + 多组读入 意思是多个t
Football Games

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1485 Accepted Submission(s): 560

Problem Description
A mysterious country will hold a football world championships—Abnormal Cup, attracting football teams and fans from all around the world. This country is so mysterious that none of the information of the games will be open to the public till the end of all the matches. And finally only the score of each team will be announced.

At the first phase of the championships, teams are divided into M groups using the single round robin rule where one and only one game will be played between each pair of teams within each group. The winner of a game scores 2 points, the loser scores 0, when the game is tied both score 1 point. The schedule of these games are unknown, only the scores of each team in each group are available.

When those games finished, some insider revealed that there were some false scores in some groups. This has aroused great concern among the pubic, so the the Association of Credit Management (ACM) asks you to judge which groups’ scores must be false.

Input
Multiple test cases, process till end of the input.

For each case, the first line contains a positive integers M, which is the number of groups.
The i-th of the next M lines begins with a positive integer Bi representing the number of teams in the i-th group, followed by Bi nonnegative integers representing the score of each team in this group.

number of test cases <= 10
M<= 100
B[i]<= 20000
score of each team <= 20000

Output
For each test case, output M lines. Output “F” (without quotes) if the scores in the i-th group must be false, output “T” (without quotes) otherwise. See samples for detail.

Sample Input
2
3 0 5 1
2 1 1

Sample Output
F
T

n个队伍,每两组队伍之间比一场,每比一场总分都要 +2 所以最后只需要判断总分和最高得分不超过最大值就行了。。。

/* * *  Author : Triose *  Email  : Triose@163.com *  Update_time : 2016.9.11 * *///#include<bits/stdc++.h>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <vector>#include <math.h>#include <time.h>#include <bitset>#include <iomanip>#include <stdio.h>#include <sstream>#include <iostream>#include <string.h>#include <iterator>#include <stdlib.h>#include <algorithm>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define inf 0x3f3f3f3f#define INF 0x7fffffff#define INFL 0x3f3f3f3f3f3f3f3fLL#define enter putchar(10)#define rep(i,a,b) for(int i = (a); i < (b); ++i)#define per(i,a,b) for(int i = (a); i >= (b); --i)#define repe(i,a,b) for(int i = (a); i <= (b); ++i)#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)#define PR(a,b) pair<a,b>#define slen(str) strlen(str)#define ds(t) int t; sf(t)#define Down(t) while(t--)#define dc(t) int t; cin >> t;#define dsD(t) ds(t); Down(t)#define dcD(t) dc(t); Down(t)#define ALL(A) A.begin(), A.end()#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define scpy(str1, str2) strcpy(str1, str2)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfP(a) printf("%d %d\n",a.fi,a.se)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define mem(a,b) memset((a),b,sizeof(a))#define fi first#define se second#define LL long long#define DB double#define isws ios::sync_with_stdio(false)const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }int n, m;int main() {#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);//  freopen("Out.txt", "w", stdout);#endif    int t;    while(~sf(t))        while(t--) {            sf(n);            LL anssum = n * (n - 1), maxsco = (n - 1) * 2;            int flag = true; LL sco, sum = 0;            rep(i, 0, n) {                sfI(sco); sum += sco;                if(sco > maxsco) flag = false;            }            if(!flag || sum != anssum) pfs("F");            else pfs("T");        }    return 0;}

5875
http://acm.hdu.edu.cn/showproblem.php?pid=5875
水的出奇的一题
Function

Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1860 Accepted Submission(s): 671

Problem Description
The shorter, the simpler. With this problem, you should be convinced of this truth.

You are given an array A of N postive integers, and M queries in the form (l,r). A function F(l,r) (1≤l≤r≤N) is defined as:
F(l,r)={AlF(l,r−1) modArl=r;l

/* * *  Author : Triose *  Email  : Triose@163.com *  Update_time : 2016.9.11 * *///#include<bits/stdc++.h>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <vector>#include <math.h>#include <time.h>#include <bitset>#include <iomanip>#include <stdio.h>#include <sstream>#include <iostream>#include <string.h>#include <iterator>#include <stdlib.h>#include <algorithm>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define inf 0x3f3f3f3f#define INF 0x7fffffff#define INFL 0x3f3f3f3f3f3f3f3fLL#define enter putchar(10)#define rep(i,a,b) for(int i = (a); i < (b); ++i)#define per(i,a,b) for(int i = (a); i >= (b); --i)#define repe(i,a,b) for(int i = (a); i <= (b); ++i)#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)#define PR(a,b) pair<a,b>#define slen(str) strlen(str)#define ds(t) int t; sf(t)#define Down(t) while(t--)#define dc(t) int t; cin >> t;#define dsD(t) ds(t); Down(t)#define dcD(t) dc(t); Down(t)#define ALL(A) A.begin(), A.end()#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define scpy(str1, str2) strcpy(str1, str2)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfP(a) printf("%d %d\n",a.fi,a.se)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define mem(a,b) memset((a),b,sizeof(a))#define fi first#define se second#define LL long long#define DB double#define isws ios::sync_with_stdio(false)const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }int n, m;const int maxn = 100010;int a[maxn], nxt[maxn];void Init() {    sf(n);    mem(nxt, -1);    repe(i, 1, n) sf(a[i]);    for(int i = n - 1; i > 0; i--) {        for(int j = i + 1; j <= n && j != -1; ) {            if(a[j] <= a[i]) {                nxt[i] = j;                break;            }            else j = nxt[j];        }    }}int Query(int l, int r) {    int ans = a[l];    int pos = nxt[l];    while(pos != -1 && pos <= r) {        ans %= a[pos];        pos = nxt[pos];    }    return ans;}int main() {#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);//  freopen("Out.txt", "w", stdout);#endif    dsD(t) {        Init();        sf(m);        int l, r;        Down(m) {            sfd(l, r);            pf(Query(l, r));        }    }    return 0;}

5876
http://acm.hdu.edu.cn/showproblem.php?pid=5876

Sparse Graph

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1654 Accepted Submission(s): 583

Problem Description
In graph theory, the complement of a graph G is a graph H on the same vertices such that two distinct vertices of H are adjacent if and only if they are not adjacent in G.

Now you are given an undirected graph G of N nodes and M bidirectional edges of unit length. Consider the complement of G, i.e., H. For a given vertex S on H, you are required to compute the shortest distances from S to all N−1 other vertices.

Input
There are multiple test cases. The first line of input is an integer T(1≤T<35) denoting the number of test cases. For each test case, the first line contains two integers N(2≤N≤200000) and M(0≤M≤20000). The following M lines each contains two distinct integers u,v(1≤u,v≤N) denoting an edge. And S (1≤S≤N) is given on the last line.

Output
For each of T test cases, print a single line consisting of N−1 space separated integers, denoting shortest distances of the remaining N−1 vertices from S (if a vertex cannot be reached from S, output “-1” (without quotes) instead) in ascending order of vertex number.

Sample Input
1
2 0
1

Sample Output
1

补图最短路,bfs + 红黑树 或者 dijkstra + priority_queue都能做。这里贴bfs + set代码:

/* * *  Author : Triose *  Email  : Triose@163.com *  Update_time : 2016.9.11 * *///#include<bits/stdc++.h>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <vector>#include <math.h>#include <time.h>#include <bitset>#include <iomanip>#include <stdio.h>#include <sstream>#include <iostream>#include <string.h>#include <iterator>#include <stdlib.h>#include <algorithm>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define inf 0x3f3f3f3f#define INF 0x7fffffff#define INFL 0x3f3f3f3f3f3f3f3fLL#define enter putchar(10)#define rep(i,a,b) for(int i = (a); i < (b); ++i)#define per(i,a,b) for(int i = (a); i >= (b); --i)#define repe(i,a,b) for(int i = (a); i <= (b); ++i)#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)#define PR(a,b) pair<a,b>#define slen(str) strlen(str)#define ds(t) int t; sf(t)#define Down(t) while(t--)#define dc(t) int t; cin >> t;#define dsD(t) ds(t); Down(t)#define dcD(t) dc(t); Down(t)#define ALL(A) A.begin(), A.end()#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define scpy(str1, str2) strcpy(str1, str2)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfP(a) printf("%d %d\n",a.fi,a.se)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define mem(a,b) memset((a),b,sizeof(a))#define fi first#define se second#define LL long long#define DB double#define isws ios::sync_with_stdio(false)const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }int n, m;const int maxn = 200010;set<int> vex[maxn];int dis[maxn];set<int> all;int s;queue<int> q;void Init() {    sfd(n, m);    mem(dis, -1);    while(!q.empty()) q.pop();    repe(i, 1, n) {        vex[i].clear();        all.insert(i);    }    int u, v;    rep(i, 0, m) {        sfd(u, v);        vex[u].insert(v);        vex[v].insert(u);    }    sf(s);    dis[s] = 0;}bool connect(int u, int v) {    return vex[u].find(v) == vex[u].end();}void bfs() {    int prev = s; q.push(s); all.erase(s);    queue<int> del;    while(!q.empty()) {        prev = q.front(); q.pop();        for(set<int>::iterator it = all.begin(); it != all.end(); it++) {            if(connect(prev, *it)) {                del.push(*it);                dis[*it] = dis[prev] + 1;                q.push(*it);            }        }        while(!del.empty()) all.erase(del.front()), del.pop();    }}void print() {    int i = 1;    for(; i <= n; i++) {        if(i != s) {            printf("%d", dis[i]);            break;        }    }    i++;    for(; i <= n; i++) {        if(i != s)            printf(" %d", dis[i]);    }    enter;}int main() {#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);//  freopen("Out.txt", "w", stdout);#endif    dsD(t) {        Init();        bfs();        print();    }    return 0;}

5877
http://acm.hdu.edu.cn/showproblem.php?pid=5877

Weak Pair

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2377 Accepted Submission(s): 736

Problem Description
You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a non-negative value ai is assigned.An ordered pair of nodes (u,v) is said to be weak if
(1) u is an ancestor of v (Note: In this problem a node u is not considered an ancestor of itself);
(2) au×av≤k.

Can you find the number of weak pairs in the tree?

Input
There are multiple cases in the data set.
The first line of input contains an integer T denoting number of test cases.
For each case, the first line contains two space-separated integers, N and k, respectively.
The second line contains N space-separated integers, denoting a1 to aN.
Each of the subsequent lines contains two space-separated integers defining an edge connecting nodes u and v , where node u is the parent of node v.

Constrains:

1≤N≤105

0≤ai≤109

0≤k≤1018

Output
For each test case, print a single integer on a single line denoting the number of weak pairs in the tree.

Sample Input
1
2 3
1 2
1 2

Sample Output
1

给你一棵树,每个节点上有权值,问你有多少对

//#include<bits/stdc++.h>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <vector>#include <math.h>#include <time.h>#include <bitset>#include <iomanip>#include <stdio.h>#include <sstream>#include <iostream>#include <string.h>#include <iterator>#include <stdlib.h>#include <algorithm>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define inf 0x3f3f3f3f#define INF 0x7fffffff#define INFL 0x3f3f3f3f3f3f3f3fLL#define enter putchar(10)#define rep(i,a,b) for(int i = (a); i < (b); ++i)#define per(i,a,b) for(int i = (a); i >= (b); --i)#define repe(i,a,b) for(int i = (a); i <= (b); ++i)#define ECH(it, A) for (typeof(A.begin()) it=A.begin(); it != A.end(); ++it)#define PR(a,b) pair<a,b>#define slen(str) strlen(str)#define ds(t) int t; sf(t)#define Down(t) while(t--)#define dc(t) int t; cin >> t;#define dsD(t) ds(t); Down(t)#define dcD(t) dc(t); Down(t)#define ALL(A) A.begin(), A.end()#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define scpy(str1, str2) strcpy(str1, str2)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfP(a) printf("%d %d\n",a.fi,a.se)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define mem(a,b) memset((a),b,sizeof(a))#define fi first#define se second#define LL long long#define DB double#define isws ios::sync_with_stdio(false)const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }int n, m; LL k;const LL maxn = 100010;struct Node {               //题目中给出的树    LL value;               //结点值    int father;             //父亲的下标    vector<int> sons;       //儿子们的下标};Node a[maxn];               //题目中的树int rt;                     //树根struct Elmt {               //线段树结点    int l, r;               //还是没偷懒,加入了l 和 r 表示这个结点维护 tag 数组的 [l, r] 区间    LL cnt;                 //数值在 [tag[l], tag[r]] 之间的数的个数    Elmt(int l = 0, int r = 0, int cnt = 0):l(l),r(r),cnt(cnt){}    int mid() { return (l + r) >> 1; }  //get mid值};Elmt tree[maxn * 4];        //线段树(对tag数组建)LL tag[maxn];               //用于离散化操作LL ans;void Init() {    sf(n); sfI(k); m = 0; ans = 0;//  tag[0] = 0LL; tag[1] = INFL;    //因为题目种不会出现a[i] == 0的情况,所以省略这句话    repe(i, 1, n) sfI(a[i].value), a[i].sons.clear(), tag[m++] = k / a[i].value, a[i].father = -1;  //输入并且初始化    int fat, son;    rep(i, 1, n) {                  //按照输入建立题目给你的树        sfd(fat, son);        a[fat].sons.push_back(son);        a[son].father = fat;    }    sort(tag, tag + m); m = unique(tag, tag + m) - tag; //离散化操作    repe(i, 1, n) {                 //没啥别的办法,所以干脆循环一下找到树根        if(a[i].father == -1) {            rt = i; break;        }    }}void Build(int root, int l, int r) {    //建树,这个操作其实可以省略。。。    tree[root].l = l; tree[root].r = r; tree[root].cnt = 0;    if(l == r) return ;    int mid = tree[root].mid();    Build(root * 2 + 1, l, mid); Build(root * 2 + 2, mid + 1, r);}int ID(LL value) {                      //根据给定值,在tag数组中找到第一个大于等于该值的数的下标    return lower_bound(tag, tag + m, value) - tag;}LL Query(int root, int l, int r) {      //询问在区间 [l, r] 中有多少个树    if(tree[root].l == l && tree[root].r == r) return tree[root].cnt;    int mid = tree[root].mid();    if(r <= mid) return Query(root * 2 + 1, l, r);    else if(l > mid) return Query(root * 2 + 2, l, r);    return Query(root * 2 + 1, l, mid) + Query(root * 2 + 2, mid + 1, r);}void Update(int root, int pos, LL dv) { //点修改    if(tree[root].l == tree[root].r) {        tree[root].cnt += dv;        return ;    }    int mid = tree[root].mid();    if(pos <= mid) Update(root * 2 + 1, pos, dv);    else Update(root * 2 + 2, pos, dv);    tree[root].cnt = tree[root * 2 + 1].cnt + tree[root * 2 + 2].cnt;   //更新}void dfs(int curr) {                    //dfs 先求cnt 再放入值 回溯过程删除    int id = ID( k / a[curr].value);    ans += Query(0, 0, id);    int pos = ID(a[curr].value);    Update(0, pos, 1LL);    for(vector<int>::iterator it = a[curr].sons.begin(); it != a[curr].sons.end(); it++) dfs(*it);    Update(0, pos, -1LL);}int main() {#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);//  freopen("Out.txt", "w", stdout);#endif    dsD(t) {        Init();        Build(0, 0, m - 1);        dfs(rt);        pfI(ans);    }    return 0;}
0 0
原创粉丝点击