2019长安大学ACM校赛网络同步赛

我太菜了 只能写四道题

A Seek Spy

水题 拿来签到

#include
#include
using namespace std;
int a[110], b[6];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof(a));
    for (int i = 0; i < 6; i++) {
      cin >> b[i];
      a[b[i]]++;
    }
    for (int i = 0; i < 6; i++) {
      if (a[b[i]] == 1) {
        cout << b[i] << endl;
      }
    }
  }
  return 0;
}

B Trial of Devil

不断找中间的值,然后找规律

#include
#include
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cout << ceil(log2(n + 1)) << endl;
  }
  return 0;
}

J Binary Number

stl里面的全排列

#include
#include
#include
#include
using namespace std;
 
 
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, m, k;
//    cin >> n >> m >> k;
    scanf("%lld%lld%lld", &n, &m, &k);
    string str;
    for (int i = 0; i < n - m; i++) str += "0";
    for (int i = 0; i < m - 1; i++) str += "1";
    set sset;
    //10110
    string pre = str;
    int  count = 1;
    do {
      if (pre != str) {
        count++;
      }
      if (count == k) {
        cout << "1" + str << endl;
        break;
      }
    } while (next_permutation(str.begin(), str.end()));
  } 
  return 0;
}

M LCM

暴力 暴力

#include
#include
#include
#include
using namespace std;
#define LL long long
const int N = 1e6+10;
LL arr[N];
LL lcm(LL m, LL n) {
  return m / __gcd(m, n) * n ;
}
int main() {
  int t;
  scanf("%d",&t);
  while (t--) {
    LL n, c;
    scanf("%lld%lld",&n,&c);
    if (c <= n) {
      printf("%lld",c*c);
      if (t != 0) {
        printf("\n");
      }
      continue;
    }
    if (sqrt(c) >= n) {
      printf("-1");
      if (t != 0) {
        printf("\n");
      }
      continue;
    }
 
    int k = 0;
    for (LL i = 1; i <= sqrt(c); i++) {
      if (c%i == 0) {
        arr[k++] = i;
        if (i*i != c) {
          arr[k++] = c/i;
        }
      }
    }
    LL sum = -1;
    for (int i = 0; i < k - 1; i++) {
      for (int j = i + 1; j < k; j++) {
        if (lcm(arr[i], arr[j]) == c && arr[i] <= n && arr[j] <= n) {
//          cout << arr[i] << " " << arr[i-1] << endl;
          sum = max(sum, arr[i] * arr[j]);
        }
      }
    }
    printf("%lld",sum);
    if (t != 0) {
      printf("\n");
    }
  }
 
  return 0;
}
/*
10
10 15
7 36
5 36
10 12
1 1
*/

除了暴力就是暴力,我真的好菜呀。(难受ing)

你可能感兴趣的:(ACM,ACM)