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

    A. Counterexample

    题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1

    因为题目里说了l-r<=50,所以可以直接枚举

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath>   
     5 #include<algorithm>  
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 
    10 LL gcd(LL n,LL m){
    11     return m==0? n:gcd(m,n%m);
    12 }
    13 
    14 int main()
    15 {
    16     LL a,b,c,l,r;
    17     cin>>l>>r;
    18     for(a=l;a<=r;a++){
    19         for(b=a+1;b<=r;b++){
    20             for(c=b+1;c<=r;c++){
    21                 if(gcd(a,b)==1&&gcd(b,c)==1&&gcd(a,c)!=1){
    22                     cout<<a<<' '<<b<<' '<<c<<"
    ";
    23                     return 0;
    24                 }
    25             }
    26         }
    27     }
    28     printf("-1
    ");    
    29 }
    View Code

    C. Diverse Permutation

    题意:给出n,原始的排列即为1 2 3 4 5 -----n,再给出k,使得新的排列中满足 |p1-p2|,|p2-p3|,..,|pn-1-pn|只有x个不相同

    因为只有x个不相同,所以有n-x个是相同的,先按照自然数的序列放前n-x个数 然后剩下的x个数则交替放置,

    自己先搜题解的时候,发现一个用hash写的,实在不懂,去翻了第二个提交的代码,发现这样做,更简单

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath>   
     5 #include<algorithm>  
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 
    10 int main()
    11 {
    12     int n,x,i=0,l,r;
    13     cin>>n>>x;
    14     for(i=1;i<=n-x;i++) printf("%d ",i);
    15     r=n;
    16     l=n-x+1;
    17 //    printf("l=%d
    ",l);
    18     for(i=1;i<=x;i++)
    19     {
    20         if(i%2) printf("%d ",r),r--;
    21         else printf("%d ",l),l++;
    22     }
    23     return 0;    
    24 }
    View Code

    这次做= =做了半小时就不想再做下去了= =连A的题意都不是很懂(数论做得太少太少拉)B现在还不太明白,C想到了也好理解= =可是当时想的是老老实实枚举,得枚到啥时候----哎----

    加油啊--go---go--go

    B再补吧= =

  • 相关阅读:
    [C语言教程]八、数组
    [C语言教程]七、函数
    超炫的时间轴jquery插件Timeline Portfolio
    jQuery 鼠标滚轮插件 jquery.mousewheel.js
    js框架Modernizr是什么东西? 他是前端开发HTML5和CSS3的强有力前端js检测类库
    HTML模块化:使用HTML5 Boilerplate模板
    实践总结
    --@ui-router--登录页通过路由跳转到内页的demo
    --@angularjs-- $location.path('/login')-$location服务用法示例
    --@ui-router——$state服务原版详解
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4311524.html
Copyright © 2011-2022 走看看