zoukankan      html  css  js  c++  java
  • Codeforces Round #213 (Div. 2) 解题报告

    Problem A Good Number

    找出数组中包含所有小于等于k的数字的数。水题

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <cstdlib>
     6 #include <algorithm>
     7 
     8 using namespace std;
     9 
    10 int n, k, vis[11];
    11 
    12 bool judge(long long num)
    13 {
    14     memset(vis, 0, sizeof vis);
    15     while(num){
    16         vis[num%10] = 1;
    17         num/=10;
    18     }
    19     for(int i=0; i<=k; i++){
    20         if(vis[i] == 0)return false;
    21     }
    22     return true;
    23 }
    24 
    25 int main()
    26 {
    27 //    freopen("in.txt", "r", stdin);
    28 
    29     long long num;
    30     while(scanf("%d%d", &n, &k)!=EOF){
    31         int ans = 0;
    32         for(int i=0; i<n; i++){
    33             scanf("%I64d", &num);
    34             if(judge(num)==true){
    35                 ans++;
    36             }
    37         }
    38         printf("%d
    ", ans);
    39     }
    40     return 0;
    41 }
    View Code

    Problem B The Fibonacci Segment

    找出长度最长的斐波那契数。主要考虑n=1的特殊情况后扫描一遍。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <cstdlib>
     6 #include <algorithm>
     7 #define LEN 100010
     8 
     9 using namespace std;
    10 
    11 int p[LEN];
    12 
    13 int main()
    14 {
    15 //    freopen("in.txt", "r", stdin);
    16     int n, ans;
    17     while(scanf("%d", &n)!=EOF)
    18     {
    19         for(int i=0; i<n; i++){
    20             scanf("%d", &p[i]);
    21         }
    22         if(n==1){
    23             ans = 1;
    24         }else{
    25             ans = 2;
    26             int loc = 2;
    27             for(int i=2; i<n; i++){
    28                 if(p[i] == p[i-1]+p[i-2]){
    29                     loc++;
    30                 }
    31                 else{
    32                     if(loc>ans)ans = loc;
    33                     loc = 2;
    34                 }
    35             }
    36             if(loc>ans)ans = loc;
    37         }
    38         printf("%d
    ", ans);
    39     }
    40     return 0;
    41 }
    View Code


    比较水只做出两道题。继续努力!

    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    (2/24) 快速上手一个webpack的demo
    (1/24) 认识webpack
    module.exports 、exports、export、export default的区别
    Git同时提交到多个远程仓库
    @codeforces
    @loj
    @bzoj
    @loj
    @bzoj
    @bzoj
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3432603.html
Copyright © 2011-2022 走看看