Codeforces Round #561 (Div. 2) (还差2题)

总结:bitset的基本操作:http://www.cnblogs.com/RabbitHu/p/bitset.html

  B题中求每行每列均有...,只要在下一行中把上一行的第一个放到最后一个就能构造满足条件的解;

  C题中这种,如果直接讨论绝对值的情况有点多,直接自己写几个例子试试会快上很多;

  E题中用bitset处理这些集合是否重合特别的快,代码也很简洁;

题目链接:http://codeforces.com/contest/1166 

A:

题意:自己看看,练练英语,英语太菜了

题解:签到就行

#include <bits/stdc++.h>
using namespace std; 

int cnt[100];

int fun(int n)
{
    if(n==0 || n==1) return 0;
    return (n-1)*n/2;
}

int main()
{
    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
    int n;  cin >> n;
    string str;
    for(int i=1; i<=n; i++)
    {
        cin >> str;
        cnt[str[0]-‘a‘]++;
    }
    long long sum=0;
    for(int i=0; i<26; i++)
        sum+=fun(cnt[i]/2)+fun(cnt[i]-cnt[i]/2);
    cout<<sum<<endl;
    return 0;
} 

B:

题意:给出一个字符串的长度n,求这由这n个字符组成的矩阵能满足每一行每一列均有a e i o u 这5个字母,若能满足条件输出这个字符串(矩阵逐行输出即可), 找不到满足条件的字符就输出-1;

题解:先求一下行和列,顺便判断一下。这个构造满足每一行每一列均有a e i o u,只要第一行能满足条件,把第一行的的第一个字符接到最后一个,作为下一行即可; 复杂度:O(n)

#include <bits/stdc++.h>
using namespace std;

string str, ans;
char ch[]={‘a‘, ‘e‘, ‘i‘, ‘o‘, ‘u‘};

int line, col;
bool myjudge(int k)
{
    for(int i=5; i*i<=k; i++)
    {
        if(k%i) continue;
        if(k/i>=5){
            line=k/i;
            col=i;
            return true;
        }
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int k; cin>>k;
    if(!myjudge(k))
        cout<<"-1"<<endl;
    else
    {
        for(int i=0; i<col; i++)
            str+=ch[i%5];
        for(int i=0; i<line; i++)
        {
            ans+=str;
            str=str.substr(1)+str[0];
        }
        cout<<ans<<endl;
    }
    return 0;
}

C:

题意:给一行数字,求能满足 abs(x+y)和abs(x-y) 所连成的区间(数轴上)包含abs(x) 和 abs(y) 所连成的区间的x,y有多少组;2≤n≤2e5

题解:很容易发现只要满足x<=2y这个条件即可,先排序,枚举最大的y即可,求y前面满足条件的所有x即可(注意这一层的x不是暴力的,直接找到一个满足条件的范围就行了);

     复杂度:O(nlogn)

#include <bits/stdc++.h>
using namespace std; 

const int MAXN=2e6+5;
int a[MAXN]; 

int main()
{
    int n; cin>>n;
    for(int i=0; i<n; i++)
    {
        int data; cin>>data;
        a[i]=abs(data);
    }
    sort(a, a+n); 

    int pos=0; long long ans=0;
    for(int i=0; i<n; i++)
    {
        while(pos<i && 2*a[pos]<a[i]) pos++;
        ans+=i-pos;
    }
    cout<<ans<<endl;
    return 0;
}

D:

感觉和数学联系很大,不会写;

E:

题意: 自己看,挺长的,练练英语

题解:直接判断是否 存在A所选择的集合是B所选择集合的子集即可,若存在就不满足条件,不存在就可以;

#include <bits/stdc++.h>
using namespace std; 

const int MAXN=1e4+5;
bitset<MAXN> a[55];
int n, m; 

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("devin.txt", "r", stdin);
    while(cin>>m>>n)
    {
        for(int i=0; i<m; i++)
        {
            a[i].reset();
            int k; cin>>k;
            for(int j=0; j<k; j++)
            {
                int p; cin>>p;
                a[i].set(p-1);
            }
        }

        for(int i=0; i<m-1; i++)
            for(int j=i+1; j<m; j++)
            {
                if((a[i]&a[j]).count()==0){
                    cout<<"impossible"<<endl;
                    return 0;
                }
            }
        cout<<"possible"<<endl;
    }
    return 0;
} 

原文地址:https://www.cnblogs.com/Yokel062/p/10914930.html

时间: 2024-07-31 03:14:36

Codeforces Round #561 (Div. 2) (还差2题)的相关文章

Codeforces Round #561 (Div. 2) 题解

Codeforces Round #561 (Div. 2) 题解 题目链接 A. Silent Classroom 水题. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 105; int n; char s[N], t[N]; int main() { cin >> n; for(int i = 1; i <= n; i++) { scanf(&q

Codeforces Round #561 (Div. 2)

C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: 数形结合: 对于某数 x 查找满足条件 y 有多少个: ①x ≥ 0 y ∈ [x/2 , 2x] ∪ [ -2x , -x/2]; ②x < 0 y ∈ [2x , -x/2] ∪ [-x/2 , -2x]; 特别注意临界值 x/2 处: AC代码: 原文地址:https://www.cnblog

Codeforces Round #426 (Div. 2)A B C题+赛后小结

最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络赛,我似乎都没用上新学的东西,能用上新学东西的题我A不了...5555555555555555 这场CF,讲真,打的心态爆炸,首先A题无限WA,赛后看下WA的那组数据是输入有一个999999999的样例,死骗子,说好的数据是1e9呢,哪能有数据是1e10-1,于是用long long,一下子Accept接收不

Codeforces Round #530 (Div. 2) (前三题题解)

总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高度的模拟,如果遇到石头就去判断一下会不会小于0其他没有什么好说的了 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int

Codeforces Round #320 (Div. 2) &quot;Or&quot; Game(好题,贪心/位运算/前缀后缀或)

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 typedef long long ll; 7 /* 8 n个数,你最多有k次操作,每次操作可以选择一个数乘以x,问所有数或(|)的最大值 9 贪心思路:选一个数进行k此乘以x操作; 因为x>=2 10 111 ---> 1111 11

Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: 1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 5 int a[3],b[3]; 6 7 int main(void) 8 { 9 int n; 10 int need = 0; 11 int sum1 = 0,sum2 = 0; 12 for(int i=1;i<=3;++i){ 13 scanf("%d&q

Codeforces Round #344 (Div. 2) C. Report 水题

#include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) #define rep(i,a,b) for(int i=a;i>=b;i--) #define RI(x) scanf("%d",&x) #define RII(x,y) scanf("%d%d",&x,&y) #d

Codeforces Round #429 (Div. 2) 841B Godsend(签到题)

B. Godsend Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an

Codeforces Round #196 (Div. 2) A. Puzzles 水题

A. Puzzles Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. S