zoukankan      html  css  js  c++  java
  • Codeforces Round #268 (Div. 2)

    A

    题意:给出n,分别给出a个数,b个数,看1到n是否都出现过

    直接模拟就可以了

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<queue> 
     9 #include<algorithm>  
    10 #define mod=1e9+7;
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 int hash[1005];
    15 
    16 int main(){
    17     int n,i,j,x,y,a,b;
    18     cin>>n;
    19     cin>>a;
    20     memset(hash,0,sizeof(hash));
    21     while(a--){
    22         cin>>x;
    23         hash[x]++;
    24     }
    25     
    26     cin>>b;
    27     while(b--){
    28         cin>>x;
    29         hash[x]++;
    30     }
    31     
    32     for(i=1;i<=n;i++){
    33         if(hash[i]==0) break;
    34     }
    35     
    36     if(i<=n) printf("Oh, my keyboard!
    ");
    37     else printf("I become the guy.
    ");
    38     return 0;
    39 }
    View Code


     

    B

    题意:分别给出p段甲的在线时间,q段乙的在线时间,再给出乙的起床时间,l,r,问能够使得甲乙都在线的起床时间有多少个

    用的一个hash数组来记录甲在线的时间,然后枚举起床时间判断乙是否在线 注意hash数组开大点,要不然会溢出

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<algorithm>  
     8 using namespace std;
     9 
    10 typedef long long LL;
    11 int hash[10005];
    12 int vis[10005];
    13 int a[10005],b[10005],c[10005],d[10005];
    14 
    15 int main(){
    16     int p,q,l,r;
    17     int ans=0;
    18     cin>>p>>q>>l>>r;
    19     for(int i=1;i<=p;i++){
    20         cin>>a[i]>>b[i];
    21         for(int j=a[i];j<=b[i];j++) hash[j]=1;
    22     }
    23     for(int i=1;i<=q;i++) cin>>c[i]>>d[i];
    24     for(int i=l;i<=r;i++){
    25         int flag=0;
    26         for(int j=1;j<=q;j++){
    27             int ll=c[j]+i;
    28             int rr=d[j]+i;
    29             for(int k=ll;k<=rr;k++){
    30                 if(hash[k]) flag=1;
    31             }
    32         }
    33         if(flag) ans++;
    34     }
    35     cout<<ans<<endl;
    36     return 0;
    37 }
    View Code

    C

    题意:给出n,代表有1,2,3,---,n个数 这n个数可以进行,加减乘的操作,每次操作的结果又重新放回这堆数中,问能否得到24

    最开始想的是bfs,后来觉得这样不对,就没有思路了

    然后搜的题解 http://www.cnblogs.com/forgot93/p/3987187.html

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<queue> 
     9 #include<algorithm>  
    10 #define mod=1e9+7;
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 
    15 int main(){
    16     int n;
    17     scanf("%d",&n);
    18     if(n<4) printf("NO
    ");
    19     else{
    20         printf("YES
    ");
    21         if(n%2==0){
    22             for(int i=n;i>=6;i=i-2){
    23                 printf("%d - %d = 1
    ",i,i-1);
    24                 printf("1 * %d = %d
    ",i-2,i-2);
    25             }
    26             printf("1 * 2 = 2
    ");
    27             printf("2 * 3 = 6
    ");
    28             printf("6 * 4 = 24
    ");            
    29         }
    30         else{
    31             for(int i=n;i>6;i=i-2){
    32                 printf("%d - %d = 1
    ",i,i-1);
    33                 printf("1 * %d = %d
    ",i-2,i-2);
    34             }
    35             printf("5 - 1 = 4
    ");
    36             printf("4 - 2 = 2
    ");
    37             printf("2 * 4 = 8
    ");            
    38             printf("8 * 3 = 24
    ");                            
    39         }
    40     }
    41     return 0;
    42 }
    View Code


     

    -因为B卡了好几天= =

    C不懂写= =

     go---go---go

  • 相关阅读:
    二叉树的深度(剑指offer)
    平衡二叉树(剑指offer)
    平衡二叉树
    513. Find Bottom Left Tree Value(得到左下角的节点)(树的层次遍历)
    637. Average of Levels in Binary Tree(一棵树每层节点的平均数)(二叉树的层序遍历)
    145. Binary Tree Postorder Traversal(非递归实现二叉树的后序遍历)
    正则表达式式总结
    re模块
    生成器 生成器函数 列表推倒式 生成器表达式
    闭包,迭代器
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4357581.html
Copyright © 2011-2022 走看看