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再补吧= =

  • 相关阅读:
    lipo命令
    Eclipse安装ADT插件
    编译vo-aacenc遇到的问题
    双MIC安卓手机录音问题
    天天动听MP3解码器性能提升50%
    Sublime Text 2结合VS2010配置C C++编译
    讯飞语音语义接口测试
    讯飞语音接口注册
    iOS阶段学习第31天笔记(UINavigationBar介绍)
    iOS App上架AppStore 会遇到的坑
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4311524.html
Copyright © 2011-2022 走看看