牛客练习赛66 A、B、C

A

#include <bits/stdc++.h>

using namespace std;

using LL = long long;

LL n;

signed main() {
  // freopen("in", "r", stdin);
  while (cin >> n) {
    LL tmp = (LL)sqrt(n);
    LL x = tmp * tmp, y = (tmp + 1) * (tmp + 1);
    if (abs(x - n) > abs(y - n)) cout << y << endl;
    else cout << x << endl;
  }
  return 0;
}

B

#include <bits/stdc++.h>

using namespace std;

using LL = long long;

inline bool scan_d(int &num) {
  char in;bool IsN=false;
  in=getchar();
  if(in==EOF) return false;
  while(in!='-'&&(in<'0'||in>'9')) in=getchar();
  if(in=='-'){ IsN=true;num=0;}
  else num=in-'0';
  while(in=getchar(),in>='0'&&in<='9'){
    num*=10,num+=in-'0';
  }
  if(IsN) num=-num;
  return true;
}

const int maxn = 1000100;
int n, q;
int a[maxn];
int vis[1 << 22];

signed main() {
  // freopen("in", "r", stdin);
  memset(vis, 0, sizeof vis);
  scan_d(n); scan_d(q);
  for (int i = 1; i <= n; i++) {
    scan_d(a[i]);
    vis[a[i]]++;
  }
  while (q--) {
    int k, x, y;
    scan_d(k); scan_d(x); scan_d(y);
    if ((a[x] ^ a[y]) == k) {
      printf("%d\n", 1);
      continue;
    }
    if (vis[a[x] ^ k] && vis[a[y] ^ k]) {
      if ((a[x] ^ k) == (a[y] ^ k)) printf("%d\n", 2);
      else printf("%d\n", -1);
      continue;
    }
    printf("-1\n");
  }
  return 0;
}

C

#include <bits/stdc++.h>

using namespace std;

using LL = long long;

inline bool scan_d(LL &num) {
  char in;bool IsN=false;
  in=getchar();
  if(in==EOF) return false;
  while(in!='-'&&(in<'0'||in>'9')) in=getchar();
  if(in=='-'){ IsN=true;num=0;}
  else num=in-'0';
  while(in=getchar(),in>='0'&&in<='9'){
    num*=10,num+=in-'0';
  }
  if(IsN) num=-num;
  return true;
}

const int maxn = 1001000;
LL n;
LL a[maxn], tot[maxn];

signed main() {
  // freopen("in", "r", stdin);
  scan_d(n);
  LL ret = 0;
  for (int i = 1; i <= n; i++) {
    scan_d(a[i]);
    tot[i] = abs(a[i] - a[i - 1]);
  }
  LL x = INT_MAX, y = INT_MAX;
  for (int i = 2; i <= n; i++) {
    if (y == INT_MAX) y = tot[i];
    else y = __gcd(y, tot[i]);
  }
  x = (y - (a[1] % y)) % y;
  printf("%lld %lld\n", y, x);
  return 0;
}
全部评论

相关推荐

头像
11-03 16:48
已编辑
百度_高级研发工程师
事实是检验真理的唯一标准。&nbsp;无论我们怎么去说,去讲述,去证明,都抵不过一个offer来得实在,无论我们怎么去复现求职中的摸爬滚打、扒皮抽筋、狼狈不堪,都抵不过你在简历写上大厂的名字(外包不算)。&nbsp;所以在我求职期间,我什么话都不说,什么话都不讲,因为没有意义,虽然我总讲过程才是意义,但只有当你上岸的那一刻,你才有资格回想在水里的挣扎,只有等你出了山,你才知道山的全貌。&nbsp;我为什么一定要离开华为OD,难道它不稳定吗,不能赚钱吗。为了证明自己,那肯定有的。其实更多的是印证我的认知是否真的正确。&nbsp;(给不了解我的人交代一下背景,在下双非一本,gap一年,华为OD外包,摸爬滚打4个月,艰难上岸百度正编)一、...
先锋战士:说得很真诚。鄙视链自古有之,学历,家庭背景,财富,权利。从小有之,小学羡慕那些当班委的,中学羡慕那些学生会的,高中羡慕尖子班拿教学金的,大学羡慕高绩点,毕业了羡慕进大厂的。工作了,又羡慕高职级的,再后来又羡慕别人早早结婚的。我想表达的观点很简单,无论是华为od还是百度,都是经历,没有孰高孰低,为了抵达下一个风景,总会付出更多东西,但不就是人生吗?正如登山,每个阶段的山,都要想办法攀登,在博主的文字中,见到了坚持和积极寻找问题解决办法的心态
学历对求职的影响
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务