[PYTHON] AtCoder Beginner Contest 084 Review of past questions

Time required

スクリーンショット 2020-03-27 12.10.48.png

Impressions

FX is defeated and withered today. The market is not rebounding and the weekend is closed to Tokyo, which is the worst. This time it's not difficult, but I made a bug in the Eratosthenes sieve. It's hard to live.

Problem A

Subtraction, no particular impression.

answerA.py


print(48-int(input()))

B problem

Check one character at a time. I made a character string from 0 to 9 and calculated whether it was in it, but it seems that it is OK even if it is "0" or more and "9" or less.

answerB.py


num=list("0123456789")
a,b=map(int,input().split())
s=input()

for i in range(a+b+1):
    if i!=a:
        if s[i] not in num:
            print("No")
            break
    else:
        if s[i]!="-":
            print("No")
            break
else:
    print("Yes")

C problem

My head was too weak and I made many mistakes. Record what time you will arrive at each station in a variable called now. Then, for each station, consider the smallest multiple of f after s and after the time you arrived at that station, and if you proceed by c from there, you will proceed to the next station. Can be solved with. I couldn't do this because I was thinking too much about FX. How stupid!

answerC.py


import math
n=int(input())
csf=[list(map(int,input().split())) for i in range(n-1)]

for j in range(n-1):
    now=0
    for i in range(j,n-1):
        if csf[i][1]>=now:
            now=csf[i][1]+csf[i][0]
        else:
            now=csf[i][1]-((csf[i][1]-now)//csf[i][2])*csf[i][2]+csf[i][0]
    print(now)
print(0)

D problem

Given the interval query, it's clear to consider the difference in cumulative sums. In other words, you should ask for "a number similar to 2017" first before calculating the query, ** Eratosthenes Sieve ** (Other Articles Introduced in 0b49891986e8bb31e148)), enumerate the prime numbers, check "Numbers similar to 2017", and consider the cumulative sum. However, the Eratosthenes sieve was buggy and I was going to check "2017-like numbers", but it took a long time just to check the prime numbers. I want to eliminate such ** careless mistakes **.

answerD.cc


#include<algorithm>//sort,Binary search,Such
#include<bitset>//Fixed length bit set
#include<cmath>//pow,log etc.
#include<complex>//Complex number
#include<deque>//Queue for double-ended access
#include<functional>//sort greater
#include<iomanip>//setprecision(Floating point output error)
#include<iostream>//Input / output
#include<map>//map(dictionary)
#include<numeric>//iota(Generation of integer sequence),gcd and lcm(c++17)
#include<queue>//queue
#include<set>//set
#include<stack>//stack
#include<string>//String
#include<unordered_map>//Map with iterator but not keeping order
#include<unordered_set>//Set with iterator but not keeping order
#include<utility>//pair
#include<vector>//Variable length array

using namespace std;
typedef long long ll;

//macro
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //I want to omit arguments such as sort
#define SIZE(x) ((ll)(x).size()) //size to size_Change from t to ll
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define MA 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second


ll sieve_check[MA+1];//i-th corresponds to integer i(1~100000)

//Implement the Eratosthenes sieve
void es(){
    FOR(i,2,MA)sieve_check[i]=1;
    //1 is a prime number, here 0 is not a prime number
    for(ll i=2;i<=1000;i++){
        if(sieve_check[i]==1){
            for(ll j=2;j<=ll(MA/i);j++){
                sieve_check[j*i]=0;
            }
        }
    }
}

signed main(){
    es();
    vector<ll> pre(MA+1);FOR(i,1,MA)pre[i]=(i%2==1&&sieve_check[i]&&sieve_check[(i+1)/2]);
    REP(i,MA)pre[i+1]+=pre[i];
    ll q;cin >> q;
    vector< pair<ll,ll> > ans(q);REP(i,q) cin >> ans[i].F >> ans[i].S;
    REP(i,q)cout << pre[ans[i].S]-pre[ans[i].F-1] << endl;
}

Recommended Posts

AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions
AtCoder Beginner Contest 071 Review of past questions
AtCoder Beginner Contest 064 Review of past questions
AtCoder Beginner Contest 082 Review of past questions
AtCoder Beginner Contest 084 Review of past questions
AtCoder Beginner Contest 068 Review of past questions
AtCoder Beginner Contest 058 Review of past questions
AtCoder Beginner Contest 043 Review of past questions
AtCoder Beginner Contest 098 Review of past questions
AtCoder Beginner Contest 114 Review of past questions
AtCoder Beginner Contest 045 Review of past questions
AtCoder Beginner Contest 120 Review of past questions
AtCoder Beginner Contest 108 Review of past questions