CF 629 A组合 B暴力 Cdp D线段树优化DP

http://codeforces.com/contest/629/problem/A

A. Far Relative’s Birthday Cake
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!

The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?

Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.

Input

In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake.

Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.

Output

Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.

Examples
input
3
.CC
C..
C.C
output
4
input
4
CC..
C..C
.CC.
.CC.
output
9
Note

If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:

  1. (1, 2) and (1, 3)
  2. (3, 1) and (3, 3)
Pieces that share the same column are:
  1. (2, 1) and (3, 1)
  2. (1, 3) and (3, 3)

题目大意:

给一个地图,每行每列为空或者有C,然后如果一行的C>=2,那么就用排列组合的方法计算就可以了。

#include
   
   
    
    

using namespace std;

typedef long long ll;
const int inf = 0x3f3f3f3f;
int atlas[100 + 5][100 + 5];

int main(){
    int n;
    scanf("%d", &n);
    char ch[105];
    for (int i = 0; i < n; i ++){
        scanf("%s", ch);
        for (int j = 0; ch[j] != '\0'; j++){
            if (ch[j] == '.') atlas[i][j] = 0;
            else atlas[i][j] = 1;
        }
    }
    ll res = 0;
    for (int i = 0; i < n; i++){
        int cnt = 0;
        for (int j = 0; j < n; j++){
            if (atlas[i][j] == 1) cnt++;
        }
        res += cnt * (cnt - 1) / 2;
    }
    for (int i = 0; i < n; i++){
        int cnt = 0;
        for (int j = 0; j < n; j++){
            if (atlas[j][i] == 1) cnt++;
        }
        res += cnt * (cnt - 1) / 2;
    }
    printf("%d\n", res);
    return 0;
}
   
   

B. Far Relative’s Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.

Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.

Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.

Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.

Output

Print the maximum number of people that may come to Famil Door's party.

Examples
input
4
M 151 307
F 343 352
F 117 145
M 24 128
output
2
input
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200
output
4
Note

In the first sample, friends 3 and 4 can come on any day in range [117, 128].

In the second sample, friends with indices 345 and 6 can come on day 140.


题目大意:

哪个区间的值最大.

思路:

其实只要暴力就可以了。。。然而我还脑残的离散化了。。。

然后得出来以后res再*2就好了

#include
   
   
    
    

using namespace std;

typedef long long ll;
typedef pair
    
    
     
      P;
const int inf = 0x3f3f3f3f;
const int maxn = 5000 + 5;
pair 
     
     
      
       a[maxn];
int m[maxn];
int fm[maxn];

int main(){
    int n;
    scanf("%d", &n);
    char ch[5];
    vector 
      
      
       
        v;
    for (int i = 0; i < n; i++){
        int f, l, r;
        scanf("%s%d%d", ch, &l, &r);
        if (ch[0] == 'F') f = 0;
        else f = 1;
        a[i] = make_pair(f, make_pair(l, r));
        v.push_back(l);
        v.push_back(r);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int i = 0; i < n; i++){
        a[i].second.first = lower_bound(v.begin(), v.end(), a[i].second.first) - v.begin();
        a[i].second.second = lower_bound(v.begin(), v.end(), a[i].second.second) - v.begin();
    }
    int res = 0;
    for (int i = 0; i < n; i++){
        int l = a[i].second.first;
        int r = a[i].second.second;
        int flag = a[i].first;
        for (int j = l; j <= r; j++){
            if (flag == 1){
                m[j]++;
                //printf("man = %d\n", m[j]);
            }
            else {
                fm[j]++;
                //printf("female = %d\n", fm[j]);
            }
        }
    }
    for (int i = 0; i < 400; i++){
        res = max(res, min(m[i], fm[i]));
    }
    printf("%d\n", res * 2);
    return 0;
}
      
      
     
     
    
    
   
   

C. Famil Door and Brackets
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings!

The sequence of round brackets is called valid if and only if:

  1. the total number of opening brackets is equal to the total number of closing brackets;
  2. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.

Gabi bought a string s of length m (m ≤ n) and want to complete it to obtain a valid sequence of brackets of length n. He is going to pick some strings p and q consisting of round brackets and merge them in a string p + s + q, that is add the string p at the beginning of the string s and string q at the end of the string s.

Now he wonders, how many pairs of strings p and q exists, such that the string p + s + q is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 109 + 7.

Input

First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively.

The second line contains string s of length m consisting of characters '(' and ')' only.

Output

Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7.

Examples
input
4 1
(
output
4
input
4 4
(())
output
1
input
4 3
(((
output
0
Note

In the first sample there are four different valid pairs:

  1. p = "(", q = "))"
  2. p = "()", q = ")"
  3. p = "", q = "())"
  4. p = "", q = ")()"

In the second sample the only way to obtain a desired string is choose empty p and q.

In the third sample there is no way to get a valid sequence of brackets.


题目大意:

一个字符串长度为n,先给一个长度为m的中间字符串s,然后问,有几组由p+s+q组成的字符串能满足一下条件

①字符串的前缀中(多余)

②最后整个字符串(和)的数量相同


思路:

表示这道题目前缀卡了我半天(因为不明白是什么意思,所以才不知道minx在for循环中的作用)

对于这道题目,首先我们先说明dp[i][j],i是目前的p的字符的个数,然后j是目前‘(’或者‘)’的个数 备注:因为‘(’和‘)’的个数是相对的,也就是说对于dp来说是可以相互公用的。所以就可以用dp[i][j] = dp[i-1][j-1]+dp[i-1][j+1]来进行计算了。

最后只要暴力枚举一下就好了,枚举的是p的长度和p中j的个数,j表示的是(比)多多少,然后通过关系就可以知道)比(多多少了。


#include
   
   
    
    

using namespace std;

typedef long long ll;
const int maxn = 2000 + 5;
const int mod = 1000000000 + 7;
const int inf = 0x3f3f3f3f;
int n, m;
ll dp[maxn][maxn];
char ch[100000 + 5];

int main(){
    dp[0][0] = 1;
    for (int i = 1; i <= maxn-1; i++){
        dp[i][0] = dp[i - 1][1];
        for (int j = 1; j <= i; j++){
            dp[i][j] = (dp[i][j] + dp[i-1][j-1] + dp[i-1][j+1]) % mod;
        }
    }
    scanf("%d%d", &n, &m);
    scanf("%s", ch);
    ll minx = inf;
    ll sum = 0;
    for (int i = 0; ch[i] != '\0'; i++){
        if (ch[i] == '(') sum++;
        else sum--;
        minx = min(minx, sum);
    }
    ll res = 0;
    for (int i = 0; i <= n - m; i++){
        for (int j = 0; j <= n - m; j++){
            if (j + minx < 0) continue;
            if (j + sum > n - m - i) break;
            res = (res + dp[i][j] * dp[n-m-i][j+sum]) % mod;
        }
    }
    printf("%I64d\n", res);
    return 0;
}
   
   

D. Babaei and Birthday Cake
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.

Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.

However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.

Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.

Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.

Output

Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Examples
input
2
100 30
40 10
output
942477.796077000
input
4
1 1
9 7
1 4
10 7
output
3983.539484752
Note

In first sample, the optimal way is to choose the cake number 1.

In second sample, the way to get the maximum volume is to use cakes with indices 12 and 4.



首先说一下这道题目的心情。。。表示这道题目很早就写出来了,然后错在了一个int和longlong的精度范围,然后整整一个下午!五个小时的时间就报废掉了!唉,不说了,都是泪啊。。。说点有用的吧(这次绝对印象深刻了)

题目大意:

给一个圆柱,然后圆柱可以往上面叠,但是叠是有条件的。

①i<j,即越往上面,在数组中的编号越大

②v[i]<v[j],即越往上面体积越大。

问,这个圆柱最大的体积是多少。


思路:

看着很像最长上升子序列,但是并不是,因为就算你是最长的,第二长的序列的体积也有可能比你大(关键是最长上升子序列的重点在于最长)。

然后我们考虑一下dp,首先,dp要开一个10W * 10W的数组,这就MLE了,其次如果要遍历所有方案,那就最坏情况是O(n*n),也不可能。于是我们就考虑到了线段树来优化这个dp。

首先,我们用一个数组ind和d分别储存这些数组,然后ind是保存原来的体积数据(体积我们就暂时用r*r*h来表示),然后我们将d数组排序,和去重即可(为的是满足a[i]<a[j]),然后我们开始枚举ind数组,然后一边往线段树里面放,一边更新维护,假设当前a[i]所在的位置是d中的pos。那么,在pos-1中的所有的数据都满足比目前位置的pos小,然后我们就只需要把之前的pos-1的这些线段位置中的最大值找出来,然后加上ind[i]就可以了。

query访问的是区间,update访问的是点,但是要维护整个所访问到的地方


#include
    
    
     
     

using namespace std;

typedef long long ll;
const int maxn = 100000 + 20;
const double pi = acos(-1);
int n;
struct point{
    int l, r;
    ll val;
    point(int l = 0, int r = 0, ll val = 0):l(l), r(r), val(val) {}
};
point tree[maxn << 3];
ll d[maxn];
ll ind[maxn];
ll mx;

void buildtree(int o, int l, int r){
    if (l == r){
        tree[o] = point (l, r, 0);
        return ;
    }
    int mid = (l + r) / 2;
    if (mid >= l){
        buildtree(o << 1, l, mid);
    }
    if (mid < r){
        buildtree(o << 1 | 1, mid + 1, r);
    }
    tree[o] = point(l, r, 0);
}

ll query(int o, int pl, int pr){
    if (tree[o].l >= pl && tree[o].r <= pr){
        return tree[o].val;
    }
    int mid = tree[o].l + (tree[o].r - tree[o].l) / 2;
    if (mid >= pl){
        mx = max(query(o << 1, pl, pr), mx);
    }
    if (mid < pr){
        mx = max(query(o << 1 | 1, pl, pr), mx);
    }
    return 0;
}

void pushup(int o){
    tree[o].val = max(tree[o << 1].val, tree[o << 1 | 1].val);
}

void update(int o, int pos, ll res){
    if (tree[o].l == tree[o].r){
        tree[o].val = max(tree[o].val, res);
        return ;
    }
    int mid = tree[o].l + (tree[o].r - tree[o].l) / 2;
    if (mid >= pos){
        update(o << 1, pos, res);
    }
    if (mid < pos){
        update(o << 1 | 1, pos, res);
    }
    pushup(o);
}

int main(){
    scanf("%d", &n);
    buildtree(1, 0, n);
    int r, h;
    for (int i = 0; i < n; i++){
        scanf("%d%d", &r, &h);
        ll tmp = (ll)r * r * h;
        ind[i] = d[i] = tmp;
    }
    sort(d, d + n);
    int lo = unique(d, d + n) - d;
    ll ans = 0, res = 0;
    for (int i = 0; i < n; i++){
        int pos = lower_bound(d, d + lo, ind[i]) - d + 1;
        mx = 0;
        query(1, 0, pos - 1);
        res = mx + ind[i];
        update(1, pos, res);
        ans = max(res, ans);
    }
    printf("%f\n", pi * ans);
    return 0;
}
    
    





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CDP Charter是由CDP(全球气候资产披露项目)发布的一项倡议,旨在通过减少碳排放、保护水资源和推动可持续林业管理等行为,实现全球可持续发展目标。该倡议通过引导企业自愿披露其环境、社会和治理(ESG)信息,有效提升了环境和社会责任意识。 CDP Charter的制定者鼓励企业采取一系列可持续的行动,其中包括:减少温室气体排放,保护水资源,推进可持续林业管理,制定可持续发展战略,增加能源效率,减少浪费等。倡议通过引导企业对ESG信息的全面披露,推动企业更加透明、负责任地运营。 CDP Charter不仅有助于企业实现自身可持续发展目标,还有助于推动全球可持续发展的进程。通过接受CDP Charter的企业将成为行业的佼佼者,为其他企业树立榜样,带动更多的企业加入到可持续发展的行列中。同时,消费者将以可持续发展为重要的购买决策因素,培育出更加环保、社会责任意识强的市场环境。 总之,CDP Charter的提出对于全球实现可持续发展目标具有重要意义,既为企业树立了可持续的发展标准,也促进了全球可持续发展的进程。 ### 回答2: CDP(Carbon Disclosure Project)是一个全球性的非营利组织,旨在鼓励和协助公司向投资者披露其企业环境、社会和治理(ESG)表现。CDP Charter是CDP对其成员公司的指南文件,规范了成员公司在披露ESG信息时应遵循的核心原则。 CDP Charter的核心原则包括:透明度、规范、合法、科学、独立和负责任。成员公司必须确保其ESG报告的透明度,将重要信息及时披露给投资者和其他利益相关者。同时,成员公司应遵守法律法规和行业准则,确保其ESG报告合法规范。报告的内容应基于科学证据,成员公司应积极关注ESG事项,并与独立专业机构合作,以确保其ESG报告质量可靠和真实。成员公司也应承担社会责任,承担其环境、社会和治理责任,并积极采取行动来改善其表现。 CDP Charter的发布标志着CDP对于ESG信息披露的整体要求趋于严格,表明CDP致力于加强对成员公司的监督和管理,以保证投资者和利益相关者对ESG信息的清晰理解和准确披露。随着ESG信息披露的重要性日益凸显,越来越多的公司开始关注ESG表现,并加入CDP成为其成员,以便更好地管理和报告其ESG信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值