luogu P2141 abacus and mental arithmetic test

 

 

Portal

 

Today there are 150 days 2019.6.11 distance NOIP2019

Recently the school began the third year we add to the prospective study up until half past eight

Greatly compressed my spare time

Ado into the topic

This is a universal - an array of questions

My idea is very simple:

a [i] denotes read digital

JS [i] represents the number of digital i appears as an addend

When the first pass read js [a [i]] value of 1

After each add two numbers (a [i] + a [j]) when updating js [a [i] + a [j]] value

However Goose (designated focus)

Is there a [i] + a [j] is updated when the number of figures necessary to determine where in read

In other words Analyzing js [a [i] + a [j]] is 1 to

This place ruined my pay just over three times

The Code

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#define enter puts("")
#define space putchar(' ')
using namespace std;
typedef long long ll;
ll read()
{
    ll op = 1, ans = 0;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') op = 0;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        ans *= 10;
        ans += ch - '0';
        ch = getchar();
    }
    return op ? ans : -ans;
}
void write(ll x)
{
    if(x < 0)
    {
        x = -x;
        putchar('-');
    }
    if(x >= 10) write(x / 10);
    putchar(x % 10 + '0');
}
ll js[20005], n, a[105], maxn, ans;
int main()
{
    n = read();
    for(int i = 1;i <= n;i++)
    {
        a[i] = read();
        js[a[i]] = 1;
        maxn = max(maxn, a[i]);
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = i + 1;j <= n;j++)
        {
            if(js[a[i] + a[j]] == 1)js[a[i] + a[j]]++;
        }
    }
    for(int i = 1;i <= maxn;i++)
    {
        if(js[i] >= 2) ans++;
    }
    write(ans);
    enter;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/thx666/p/11006262.html