[CCPC2017]湘潭邀请赛

题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/index/p/14/

D.模拟,按照原图每一个字符变成一个a*b的矩阵构造新矩阵。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 const int maxn = 111;
 5 int n, m, a, b;
 6 char G[maxn][maxn];
 7 char GG[maxn][maxn];
 8
 9
10 int main() {
11     // freopen("in", "r", stdin);
12     while(~scanf("%d%d%d%d",&n,&m,&a,&b)) {
13         memset(GG, 0, sizeof(GG));
14         for(int i = 1; i <= n; i++) scanf("%s", G[i]+1);
15         for(int i = 1; i <= n; i++) {
16             for(int j = 1; j <= m; j++) {
17                 for(int ii = 1; ii <= a; ii++) {
18                     for(int jj = 1; jj <= b; jj++) {
19                         GG[(i-1)*a+ii][(j-1)*b+jj] = G[i][j];
20                     }
21                 }
22             }
23         }
24         for(int i = 1; i <= n*a; i++) printf("%s\n", GG[i]+1);
25     }
26 }

E.由于选取的区间点l,r都是不重复的,那么可以将整个问题描述为前缀和取2*m个点,每个点都不重复。

对整个数列排序,从两头取就行了。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 typedef long long LL;
 5 const int maxn = 100100;
 6 LL a[maxn], s[maxn];
 7 int n, m, c;
 8
 9 int main() {
10     // freopen("in", "r", stdin);
11     while(~scanf("%d%d%d",&n,&m,&c)) {
12         memset(s, 0, sizeof(s));
13         for(int i = 1; i <= n; i++) {
14             scanf("%I64d", &a[i]);
15             s[i] = s[i-1] + a[i];
16         }
17         sort(s, s+n+1);
18         LL ret = 0;
19         LL tmp = 0;
20         int lo = 0, hi = n;
21         for(int i = 1; i <= m; i++) {
22             tmp += abs(s[hi]-s[lo]) - c;
23             hi--; lo++;
24             ret = max(ret, tmp);
25         }
26         printf("%I64d\n", ret);
27     }
28     return 0;
29 }

H.先用djikstra求出这棵树上的树直径,两个端点的再向其余边,最大的值加入到mst的权值中就行了。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 typedef long long LL;
 5 typedef pair<LL, LL> pii;
 6 typedef struct Edge { LL v, w, next; }Edge;
 7 const LL maxn = 100100;
 8 LL n, hcnt;
 9 LL head[maxn];
10 Edge edge[maxn<<1];
11 LL d[2][maxn];
12
13 void adde(LL u, LL v, LL w) {
14     edge[hcnt].v = v, edge[hcnt].w = w;
15     edge[hcnt].next = head[u]; head[u] = hcnt++;
16 }
17
18 LL dij(LL id, LL u) {
19     memset(d[id], -1, sizeof(d[id]));
20     priority_queue<pii> pq;
21     pq.push(pii(0, u)); d[id][u] = 0;
22     while(!pq.empty()) {
23         pii tmp = pq.top(); pq.pop();
24         LL pw = tmp.first;
25         u = tmp.second;
26         for(LL i = head[u]; ~i; i=edge[i].next) {
27             LL v = edge[i].v, w = edge[i].w;
28             if(d[id][u] < pw) continue;
29             if(d[id][v] == -1 || d[id][v] > d[id][u] + w) {
30                 d[id][v] = d[id][u] + w;
31                 pq.push(pii(d[id][v], v));
32             }
33         }
34     }
35     LL w = 0;
36     for(LL i = 1; i <= n; i++) {
37         if(w < d[id][i]) {
38             w = d[id][i]; u = i;
39         }
40     }
41     return u;
42 }
43
44
45 int main() {
46     // freopen("in", "r", stdin);
47     LL u, v, w;
48     while(~scanf("%I64d", &n)) {
49         hcnt = 0;
50         memset(head, -1, sizeof(head));
51         for(LL i = 0; i < n - 1; i++) {
52             scanf("%I64d%I64d%I64d",&u,&v,&w);
53             adde(u, v, w); adde(v, u, w);
54         }
55         LL lo = dij(0, 1);
56         LL hi = dij(1, lo);
57         dij(0, hi);
58         LL ret = d[0][lo];
59         for(LL i = 1; i <= n; i++) {
60             if(i == lo || i == hi) continue;
61             ret += max(d[0][i], d[1][i]);
62         }
63         printf("%I64d\n", ret);
64     }
65 }

I.简单推下会发现整个式子表示的是一个数列上选取两个点,求两个点的最小间隔。最小间隔是gcd(n,m),那么选中间的位置就会使式子最小。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 typedef long long LL;
 5 const int maxn = 111;
 6 LL n, m;
 7 LL gcd(LL x, LL y) {
 8     return y == 0 ? x : gcd(y, x % y);
 9 }
10
11 int main() {
12     // freopen("in", "r", stdin);
13     while(cin >> n >> m) {
14         LL a = gcd(n, m);
15         LL b = 2 * n * m;
16         LL g = gcd(a, b);
17         a /= g, b /= g;
18         cout << a << "/" << b << endl;
19     }
20 }

A.相当于求伴随矩阵的第一列,用高斯消元求出矩阵的逆,输出第一行。

板子挂了啊。

时间: 2024-08-24 04:16:33

[CCPC2017]湘潭邀请赛的相关文章

2018年湘潭邀请赛

题目链接: http://acm.hdu.edu.cn/listproblem.php?vol=53 A题: 题意: 总共有sum(a[i])篇文章,文章含有i条引用的文章数是ai,求最大的h使得最少有h篇文章含有至少h条引用. 思路: 二分,不过一开始把i和ai的含义读反wa了几发. 代码实现如下: 1 #include <set> 2 #include <map> 3 #include <deque> 4 #include <queue> 5 #incl

2014湘潭邀请赛 C题 湘大OJ 1205 Range (单调栈)

Problem Description For an array, the range function is defined below: Range(A)=Max(A)-Min(A)+1; For example, suppose A={1,2,3,4,5}, then Range(A)=5-1+1=5. Now, given an array A(length≤100000), you are going to calcalute the sum of all subarray's ran

XTU 1261 - Roads - [最小割][2017年湘潭邀请赛(江苏省赛)B题]

之前在网上搜了一个下午没搜到这道题的题解,然后同时又对着叉姐写的两行字题解看了一个下午: 虽然基本上已经知道了这题的思路,但愣是因为自己代码实现起来太繁复,外加不确定正确性,没敢码-- 但是一道题肝了一下午没肝出来,就要放弃的话,怕是太扎心了,忍不住就跑去ICPCCamp.Post问叉姐了(https://post.icpc-camp.org/d/715-2017-b-roads) 看了叉姐的对于我的几个问题的回复,我总算肯定了我的思路,而且叉姐还在下面给了标程,当时可以说心情非常愉悦: 听起来

CCPC2017湘潭 1263 1264 1267 1268

1263 拉升一下就A了 #include <iostream> #include <vector> #include <algorithm> #include <queue> #define LL long long int using namespace std; int main() { cin.sync_with_stdio(false); int n,m,a,b; while(cin>>n>>m>>a>&g

湘潭邀请赛——Alice and Bob

Alice and Bob Accepted : 133   Submit : 268 Time Limit : 1000 MS   Memory Limit : 65536 KB  Problem Description The famous "Alice and Bob" are playing a game again. So now comes the new problem which need a person smart as you to decide the winn

2017 CCPC 湘潭邀请赛

Problem A Problem B Problem C Problem D 直接输出即可. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --i) const int N = 1e2 + 10; int c[N][N], f[N][N]; i

[题解]2018湘潭邀请赛

A.Easy h-index 题目描述 The h-index of an author is the largest h where he has at least h papers with citations not less than h.Bobo has published many papers. Given a0, a1, a2 ,..., an which means Bobo has published a i papers with citations exactly i ,

Just h-index 2018湘潭邀请赛

题目描述 The h-index of an author is the largest h where he has at least h papers with citations not less than h . Bobo has published n papers with citations \(a_1 , a_2 ,..., a_n\) respectively. One day, he raises q questions. The $i_{th} $question is d

2018 CCPC 湘潭邀请赛 &amp; 2018 JSCPC

Problem A Problem B Problem C Problem D Problem E Problem F Problem G Problem H Problem I Problem J Problem K 原文地址:https://www.cnblogs.com/cxhscst2/p/9062107.html