zoukankan      html  css  js  c++  java
  • 洛谷P1154 奶牛分厩 数学

     洛谷P1154 奶牛分厩  数学
    有一个有趣的性质,就是如果 ai-aj = x 那么 x 就不可能是答案
    设 ai = kx+b
    则 aj = kx+b+x = (k+1)x+b
    所以 x 不可能为模数

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <string>
     6 #include <algorithm>
     7 #include <iomanip>
     8 #include <iostream>
     9 #include <bitset>
    10 using namespace std ;
    11 
    12 int n,a[5001] ;
    13 bitset <1000011> f ;
    14 
    15 int main() 
    16 {
    17     scanf("%d",&n) ;
    18     for(int i=1;i<=n;i++) scanf("%d",&a[ i ]) ;
    19     for(int i=1;i<=n-1;i++) 
    20         for(int j=i+1;j<=n;j++) 
    21             f[abs(a[i]-a[j])] = 1 ; 
    22     for(int i=n;i<=1000000;i++) 
    23         if(f[i]==0) 
    24         {
    25             printf("%d
    ",i) ;
    26             return 0 ;
    27         }
    28     return 0 ;
    29 }
  • 相关阅读:
    登录界面
    动手动脑
    关于二进制
    Java考试
    D
    威尔逊定理 k!%p
    11.46.2020质检
    最长上升序列输出方案
    问题 G: 汽车的最终位置
    奶牛大会(二分)
  • 原文地址:https://www.cnblogs.com/third2333/p/6877974.html
Copyright © 2011-2022 走看看