2018 National multi-school algorithm winter training Camp Practice competition (third session)

Source: Internet
Author: User
Tags cas

"Topic Connection"

Due to the fact that many of the original questions were found during the game, the original code was copied directly and later prepared for rewriting.

A-the uncommon husband

The answer is $\left\lfloor {\sum\limits_{i = 1}^n {{{\log}_8}i}} \right\rfloor + 1$, due to the problem of data range, can be asked offline, and then $1$ to $10^7$ run again the answer is all over.

Heard that there is a $o (1) $ formula that says it does not push ...

#include <bits/stdc++.h>using namespace Std;int ans[1000010];struct Q {  int n;  int id;  int ans;} S[1000010];d ouble work (int x) {  return log10 (1.0 * x)/log10 (8.0);} BOOL CMP (Q & A, Q & B) {  return A.N < B.N;} int main () {  int n;  int T;  Cin >> T;  for (int cas = 1; CAs <= T; cas + +) {    scanf ("%d", &S[CAS].N);    S[cas].id = CAs;  }  Sort (s + 1, s + 1 + T, CMP);  int now = 0;  Double A = 0.0;  for (int i = 1; I <= T; i + +) {while    (now < S[I].N) {now      + +;      A + = Work (now);    }    Ans[s[i].id] = (int) A + 1;  }  for (int i = 1; I <= T; i + +) {    printf ("%d\n", Ans[i]);  }  return 0;}

B-A small problem

Chinese remainder theorem, $n >20$ without solution, otherwise run China remainder theorem

Code later.

C-Guardian White up

This question and POJ 24,091 kind, only the data range expands a bit, pay attention to take the mold.

Code later.

D-Calf vs. Small Guest

Only $1$ and $2$ calves will win, the rest are small customers win.

#include <bits/stdc++.h>using namespace Std;int main () {  int n;  while (CIN >> N) {    if (n > 2) printf ("xiaoke\n");    else printf ("xiaoniu\n");  }  return 0;}

E-Attack It! Factorial

Large number operations, directly on the Java.

Import java.math.bigdecimal;import java.math.biginteger;import java.util.*;p ublic class Main {static Scanner cin = new Sc Anner (system.in);p ublic static void Main (string[] args) {while (Cin.hasnext ()) {int n = cin.nextint (); BigInteger ans = biginteger.one;for (int i = 1; I <= n; i + +) {ans = ans.multiply (biginteger.valueof (i));} System.out.println (ANS);}}

F-Calf re-war

I am looking at the sample to guess, except that the number of 1 is all different or up to see if it is $0$. The reason is to study it in depth.

#include <bits/stdc++.h>using namespace Std;int a[1000];int n;int main () {  while (~scanf ("%d", &n)) {    if (n = = 0) break;    int ok = 0;    for (int i = 1; I <= n; i + +) {      scanf ("%d", &a[i]);      if (a[i]! = 1) ok ^= a[i];    }    if (OK) printf ("win\n");    else printf ("lose\n");      }  return 0;}

G-Flood problem

$ shaped pressure dp$.

$DP [i]$ indicates that the number of digits divisible by the $i$ state can be divided by a few, and the number of digits that can be divisible by the state $i$ is calculated backwards, $DP [0]$ is the answer. Look at the code and you'll understand.

#include <bits/stdc++.h>using namespace Std;long long X[10];long long St[1000];long long dp[1000];void init () {
   
    x[0] = 2;  X[1] = 5;  X[2] = one;  X[3] =;  for (int j = 0; J < (1 << 4); j + +) {    st[j] = 1;    for (int p = 0; p < 4; p + +) {      if (J & (1 <<p)) St[j] *= x[p];    }   cout << J << "<< St[j] << Endl;  }} int main () {  init ();  Long long N;  while (~SCANF ("%lld", &n)) {    long long ans = 0;    for (int i = 0; I <=; i + +) {      dp[i] = 0;    }    for (int i = 0; i <; i + +) {      Dp[i] = N/st[i];    }    for (int i = +; I >= 0; I-) {for      (int j = i + 1; j <=; J + +) {        if ((i | j) = = j) {          dp[i]-= Dp[j] ;        }      }    }    printf ("%lld\n", Dp[0]);  }  return 0;}
   

H-Go Left

This question and POJ 16,961 kind, each pole angle sorts to find the first one can.

Code later.

I-Triangles

The Pique theorem, this question and hdu 17,051 kind.

Code later.

2018 National multi-school algorithm winter training Camp Practice competition (third session)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.