Codeforces Round #438 A+B+C Contest 868

本文解析了三道编程题目,包括暴力求解字符串问题、时钟指针角度判断及二进制位运算难题。提供了完整的代码实现,并附带了解题思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

三道水题。

题目链接:点击打开链接


A:一看到n<=100 直接暴力

#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=110;

string t,a[maxn];
int main(){
    cin>>t;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    bool f=false;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            string tmp=a[i]+a[j];
            if(tmp.find(t)!=-1){
                f=true;
                break;
            }
        }if(f) break;
    }
    if(f) printf("YES\n");
    else printf("NO\n");
	return 0;
}

B:将钟表上的时针分针秒针所指的位置转化成度数,然后枚举各种情况。
/*
2017年10月6日10点56分
AC
*/
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    int h,m,s,t1,t2;
    scanf("%d%d%d%d%d",&h,&m,&s,&t1,&t2);
    double dh,dm,ds,dt1,dt2;
    dt1=t1%12*30.0;
    dt2=t2%12*30.0;
    ds=s%60*6.0;
    dm=m%60*6.0+s*0.1;
    dh=h%12*30.0+dm*1.0/12;
    //printf("%lf %lf %lf \n",dh,dm,ds);
    double a[3],b[2];
    a[0]=ds;
    a[1]=dm;
    a[2]=dh;
    b[0]=dt1;
    b[1]=dt2;
    sort(a,a+3);
    sort(b,b+2);
    if(b[0]>a[0]&&b[1]<a[1]||b[0]>a[1]&&b[1]<a[2]||b[0]>a[2]&&b[1]>a[2]||b[0]<a[0]&&b[1]>a[2]||b[1]<a[0]||b[0]>a[2]) printf("YES");
    else printf("NO\n");

	return 0;
}

C:一道脑筋急转弯,代码参考自:http://www.voidcn.com/article/p-cwboylbk-boa.html
      思路就是把输入的每一行看成二进制数,如果存在满足要求的题目,那么一定有两行相与之后的值为0.那么我们就去找这样的两个二进制数字,直接暴力会T,有个技巧,因为K最大为4,那么我们只要把每一种二进制k出现与否存在b[16],出现一次b[k]++,然后在暴力2^2k找是否存在这样两个二进制相与为0即可。
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn][5],b[16];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++){
            int num=0;
        for(int j=0;j<k;j++){
            scanf("%d",&a[i][j]);
            num|=a[i][j]<<(k-1-j);
        }
        b[num]++;
    }
    bool f=false;
    for(int i=0;i<(1<<k);i++){
        //printf("%d\n",b[i]);
        for(int j=0;j<(1<<k);j++){
            //printf("%d\n",b[i]&b[j]);
            if((i&j)==0&&b[i]&&b[j]){
                //printf("YES\n");
                f=true;
            }
        }

    }
    if(f)
        printf("YES\n");
    else
        printf("NO\n");

	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值