Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)

  A题,水题,不过我写的时候少考虑了一个细节导致WA了一发。

  B题,水题,判断一行内元音字母的个数是不是等于p[i]即可。

  C题,好题,反过来思考,用并查集离线处理。每次如果能合并就合并并更新答案即可。代码如下:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <iostream>
 5 #include <queue>
 6 using namespace std;
 7 typedef long long ll;
 8 const int N = 100000 + 5;
 9
10 int n;
11 ll a[N];
12 int root[N];
13 bool have[N];
14 ll ans[N];
15 int des[N];
16 int find(int x) {return x == root[x] ? x : root[x] = find(root[x]);}
17 void init()
18 {
19     for(int i=1;i<=n;i++) root[i] = i;
20     memset(have,false,sizeof have);
21 }
22
23 int main()
24 {
25     cin >> n;
26     for(int i=1;i<=n;i++) scanf("%I64d",a+i);
27     for(int i=1;i<=n;i++) scanf("%d",des+i);
28     init();
29     ll now = 0;
30     for(int i=n;i>=1;i--)
31     {
32         int p = des[i];
33         have[p] = true;
34         now = max(now, a[p]);
35         if(p - 1 >= 1 && have[p-1])
36         {
37             int rx = find(p-1);
38             int ry = find(p);
39             root[ry] = rx;
40             a[rx] += a[ry];
41             now = max(now, a[rx]);
42         }
43         if(p + 1 <= n && have[p+1])
44         {
45             int rx = find(p);
46             int ry = find(p+1);
47             root[ry] = rx;
48             a[rx] += a[ry];
49             now = max(now, a[rx]);
50         }
51         ans[i-1] = now;
52     }
53     for(int i=1;i<=n;i++) printf("%I64d\n",ans[i]);
54     return 0;
55 }

C

  D题,之前做过一次,这次还是没有能够完全正确的解答出来(而且之前写的博客有点问题)。。正确的贪心思路是,每次取出集合中最大的元素,不断地除以2直到这个数不在集合中出现为止。再把当前这个数放到集合中,如果不能够创造出新的数,那么就结束算法。只除1次和一直除到不能再除为止这两种思路都是错误的。代码如下:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <iostream>
 5 #include <queue>
 6 #include <map>
 7 #include <set>
 8 using namespace std;
 9 typedef long long ll;
10 const int N = 100000 + 5;
11
12 int n;
13 set<int> S;
14
15 int main()
16 {
17     cin >> n;
18     for(int i=1;i<=n;i++)
19     {
20         int t;
21         scanf("%d",&t);
22         S.insert(t);
23     }
24     while(1)
25     {
26         set<int>::iterator it = S.end();
27         it--;
28         int now = *it;
29         //S.erase(it);
30         while(S.find(now) != S.end() && now) now >>= 1;
31         if(now == 0) break;
32         S.erase(it);
33         S.insert(now);
34     }
35     for(set<int>::iterator it=S.begin();it!=S.end();it++) printf("%d ",*it);
36     puts("");
37     return 0;
38 }

D

时间: 2024-08-02 10:55:15

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)的相关文章

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)C. Destroying Array(想法题)

传送门 Description You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the ar

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> 2 #include <iostream> 3 #include <queue> 4 #include <stdio.h> 5 #include <string.h> 6 #include <algorithm> 7 #include <string> 8 #include

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array -- 逆向思维

原题中需要求解的是按照它给定的操作次序,即每次删掉一个数字求删掉后每个区间段的和的最大值是多少. 正面求解需要维护新形成的区间段,以及每段和,需要一些数据结构比如 map 和 set. map<int, LL>interval2Sum来维护区间段(u->v),mulitset<LL>sum 来维护最大值.那么每次删除操作后,都需要去interval2Sum中找到对应区间,然后erase掉, 重新生成left -> delId -> right两个区间段,最后在ma

C. Destroying Array 并查集/线段树 Intel Code Challenge Elimination Round (Div. 1 + Div. 2, combined)

题目大意就是给一个初始数组,每次删除一个点,问你剩下的连续的那些点中,最大的和是多少 2种做法 第一种是离线并查集  (这里是不会用那个res[]数组,将子的权值挪给父亲那里. 第二种是线段树区间合并.(练手 ///线段树 1 #include <algorithm> 2 #include <stack> 3 #include <istream> 4 #include <stdio.h> 5 #include <map> 6 #include &

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing

C. Ray Tracing There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

C 模拟 题意:给的是一个矩形,然后√2 的速度走,如果走到边上就正常反射,走到角上,暂停反射,我们知道要不循环要不暂停,记录走到的点最短时间 /************************************************************************* > File Name: c.cpp > Author: opas_chenxin > Mail: [email protected] > Created Time: 2016年10月08日

codeforces Intel Code Challenge Final Round (div.1 + div.2 combined)

比赛水掉3题rk559 rating+115 赛后切掉C n年没打cf了终于又重新变蓝了,果然太弱... 1.A题  Checking the Calendar 给定两个星期几,问是否可能分别是两个月的第一天. 水题暴力枚举月份 #include<cstdio> #include<cstring> #include<cstdlib> #include<vector> #include<algorithm> #include<function

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A

Description You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month w

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最小的情况,并按字典序输出 思路:字典序 例如 aaaaaaab < ab  也就是说,如果满足要求的取法中取到了b 那么所有的a都应该被取到,这样才可以保证字典序最小,那么也就是说在26个字母中找到一定要被取的最大字母,然后再确定最大的字母的个数,比它小的全部要取 AC代码: 1 #include