[Title] CCF CSP algorithm second question practice (update)

/*
Questions Number: 201912-2
Questions Name: Trash site
Subject description:
By aerial drone that we have yet to know the location of garbage clean-up of n, the coordinates where the first i (1 <= i <= n) is at (xi, yi), to ensure that all coordinates are integers.
We hope to establish some trash in the garbage concentrated. Specifically, for a position (x, y) to establish the suitability of the recycle bin, we mainly consider the following:
· (X, y) coordinates must be an integer, and there exists garbage;
· Four vertical positions left neighbor, i.e. (x, y + 1), (x, y-1), (x + 1, y) and (x-1, y) at all the refuse must be present;
* Further, we will meet the above two conditions site. The scores are a natural number of not more than 4, expressed in (x ± 1, y ± 1) there are four pairs of angular positions exist several garbage.
Now, you look at the statistics the number of site selection for each score.
*/

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std; 

class data
{
public :
     int x, y, n = - 1 ;
};

int main ()
{
    int n, x, y, cnt1, cnt2, out[5]{0};
    vector<data> dat;
    cin >> n;
    dat.reserve(n);
    for (int i = 0; i < n; ++i)
    {
        data d;
        cin >> d.x >> d.y;
        dat.push_back(d);
    }
    
    for (auto& i: dat)
    {
        cnt1 = 0;
        CNT2 = 0 ;
        for (j car: in that)
        {
            if(i.x == j.x && abs(i.y - j.y) == 1)
                cnt1++;
            else if(i.y == j.y && abs(i.x - j.x) == 1)
                cnt1++;
            else if(abs(i.x - j.x) == 1 && abs(i.y - j.y) == 1)
                Cnt2 ++ ;
        }
        if (cnt1 == 4)
        {
            i.n == cnt2;
            out[cnt2]++;
        }
    }
    cout << out[0] << endl << out[1] << endl << out[2] << endl << out[3] << endl << out[4];
    return 0;
}

 

/*
Questions Number: 201909-1
Questions Name: Bob apples
Title Description
Xiao Ming in his orchard planted some apple trees. In order to ensure the quality of apples in the planting process to several rounds thinning operation, that is ahead of the bad apples from the trees to be removed. 
Thinning operation is started before the first round, the number of recorded Xiaoming apples on each tree. Thinning operation each round, the number of recorded Xiaoming are removed from Apple every tree.
At the end of the final round of thinning operations, please help Xiao Ming statistically relevant information.
* / #include <iostream> #include <vector> using namespace std; int main () { you TURNS, treeNum, appleNum, T { 0 }, D { 0 }, E { 0 }; cin >> treeNum; vector<int> drop(treeNum, 0); for (int i = 0; i < treeNum; ++i) { vector<int> vt; cin >> turns; vt.resize(turns+1); vt[0] = turns; for (int j = 1; j <= turns; ++j) cin >> vt[j]; appleNum = vt[1]; for (int k = 2; k <= turns; ++k) { if (vt[k] <= 0) { appleNum + = vt [k]; } else { drop[i] += appleNum - vt[k]; appleNum = vt [k]; } } T += appleNum; } for (int i = 0; i < treeNum; ++i) { if (drop[i] > 0) D++; if (drop[i] > 0 && drop[(i+1)%treeNum] > 0 && drop[(i+treeNum-1)%treeNum] > 0) E++; } cout << T << ' ' << D << ' ' << E; return 0; }

 

/*
Questions Number: 201903-2
Questions Name: 24.2
Description [title]
Define each game consists of four numbers from 1-9, and 3 composed of four operators, operators will ensure four numbers separated twenty-two, brackets and other characters do not exist, 
the order of operations in accordance with the order of the four arithmetic operations. Wherein the symbol + represents addition, subtraction by the symbol - represents a multiplication lowercase letters x, the division symbol / represents.
Division is divisible in the game, for example, 2/3 = 0,3 / 2 = 4/2 = 2. The teacher gave you the solution n a game, you write a program to verify whether the results of each game is 24.
*/ #include <iostream> #include <stack> using namespace std; void culculate(stack<int> &nums, stack<char> &ops, bool tag) { int num2{nums.top()}; nums.pop(); int num1{nums.top()}; nums.pop(); int result; char op{ops.top()}; ops.pop(); switch(op) { case '+': result = num1 + num2; break; case '-': tag ? result = num1 - num2 : result = num2 - num1; break; case 'x': result = num1 * num2; break; case '/': result = num1 / num2; break; } nums.push(result); } inline int priority ( char on) { if (at == ' + ' || on == ' - ' ) return 1 ; else return 2 ; } int main () { string input; int n, result; stack<char> ops, ops2; stack<int> nums, nums2; cin >> n; for (int i = 0; i < n; ++i) { cin >> input; for (int i = 0; i < 7; ++i) { if (i % 2 == 0) { nums.push(input[i] - '0'); if (!ops.empty() && priority(ops.top()) == 2) culculate(nums, ops, true); } else ops.push(input[i]); } while(!ops.empty()) { ops2.push(ops.top()); ops.pop(); } while(!nums.empty()) { nums2.push(nums.top()); nums.pop(); } while(!ops2.empty()) culculate (nums2, ops2, false ); result = nums2.top(); nums2.pop(); if (result == 24) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }

 

Guess you like

Origin www.cnblogs.com/joeyzhao/p/12286337.html