CSUFT2018 's second personal game of the year spring

Source: Internet
Author: User
Tags stdin strlen first row
CSUFT2018 's second personal game of the year springA:A-A Very hard Question b:linear Algebra Test d:dice Game e:the Architect Omar f:building Numbers H:eyad an D Math I:move between Numbers K:malek and Summer semester a:a Very Hard Question

Do not want to write a puzzle, read test instructions and then finished

#include <bits/stdc++.h>


using namespace std;

int main ()
{

    int T;
    scanf ("%d", &t);
    while (t--) {
        int x, y;
        scanf ("%d%d", &x,&y);
        printf ("%d\n", X*100/(100+y));

    }
    return 0;
}
b:linear Algebra Test

The main idea: is to give the row of n matrices, ask which matrices can be multiplied.
problem-solving ideas : Nothing else, to speed up the search speed, so use map storage, find quickly.

#include <bits/stdc++.h>

using namespace std;
Map<long,long> Row,col;

Long Long fun (long A,long long b) {
    return a*b;
}
int main ()
{
    //freopen ("In.txt", "R", stdin);
    int T;
    scanf ("%d", &t);
    while (t--)
    {
        row.clear ();
        Col.clear ();
        int n;
        scanf ("%d", &n);
        int u,v;
        for (int i=0;i<n;i++) {
            scanf ("%d%d", &u,&v);
            if (Row.count (u) ==0) row[u]=1;
            else row[u]++;
            if (Col.count (v) ==0) col[v]=1;
            else col[v]++;
        }
        Long long sum=0;
          For (Map<long,long>::iterator I=row.begin (); I!=row.end (); i++) {
            if (Col.count (I->first)!=0)
                sum + = Fun (I->second,col[i->first]);
        }
        printf ("%lld\n", sum);
    }
    return 0;
}
D:dice Game

The main topic : Give the dice six side, the dice did not scroll once plus the number above, asked to N, the minimum number of steps to roll, each dice from 1 rolling, rolling only 90 °.
problem analysis : Less than 12 points can be directly done, more than 12 points, each time 1->5->6 can be the fastest, find the law is good.

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define LL Long long
const int maxn=100005;

int a[25]={0,1,1,1,1,1,
            2,3,2,2,2,
            2,3,3,3,3,
            3,4,4,4,4,4,4};

int main ()
{
//    freopen ("In.txt", "R", stdin);
    int t,n;
    scanf ("%d", &t);
    int Yu,bei;
    while (t--)
    {
        int ans=0;
        scanf ("%d", &n);
        if (n==1)
            cout<<-1<<endl;
        else if (n<=11)
            cout<<a[n]<<endl;
        else if (n>11)
        {
            while (n>11) {
                n-=11;
                ans+=2;
            }
            if (n==7)
                ans-=1;
            Ans+=a[n];
            cout<<ans<<endl;
        }}}



e:the Architect Omar

Topic: The topic given four strings, to be found in other strings, and will only appear in the first few characters.
problem Analysis : so very simple. Match string, statistic quantity, classify according to the topic request is good.

#include <bits/stdc++.h> using namespace std;
Char str[3][10] = {"Living", "kitchen", "Bed"};
Char s[55];
    BOOL Fun1 (char *s1,char *s2) {int len = strlen (S2);
    if (strlen (S1) <len) return false;
    for (int i=0;i<len;i++) {if (S1[i]!=s2[i]) return false;
} return true;
    } int Fun () {if (FUN1 (s,str[0])) return 1;
    if (FUN1 (s,str[1])) return 2;

if (FUN1 (s,str[2])) return 3;
    } int main () {//freopen ("In.txt", "R", stdin);
    int T;
    scanf ("%d", &t);
        while (t--) {int n;
        scanf ("%d", &n);
        int ans[3]={0,0,0};
            for (int i=0;i<n;i++) {cin>>s;
            Switch (fun ()) {case 1:ans[0]++;
            Break
            Case 2:ans[1]++;
            Break
            Case 3:ans[2]++;
            Break
        }} int minn = ans[0];
        if (ANS[1]&LT;MINN) minn = ans[1];
        if (Ans[2]/2<minn)    Minn = ANS[2]/2;
    printf ("%d\n", Minn);
} return 0; }
f:building Numbers

The main topic : to the T Group input, each group of the first row to two numbers n and Q, followed by a row of n numbers, and then the Q Line of inquiry, each line asked two numbers, L and R, representing the range. Each number of n-row numbers can be incremented from 1 in two ways, such as 8 can be 1->2->4->8; as 11 can 1->2->4->8->9->10->11, but there is a faster way 1->2- >4->5->10->11, only five steps can be completed in 11 increments. So find the minimum increment number of numbers within the given range [L,r] and.
Problem Solving Ideas :
The first question: what is the minimum increment for a single number? The answer is multiply by 2, so for this number, we remove as much as 2, can not be divided by 2 to be, the upside is the best, this is because in the increment process, the closest to the target number times two of the increase effect is the most obvious, so the extra need to multiply by two. So upside down, N is divided by two, not minus 1, except 2. The approximate speed of such a child is obviously the best.
The second problem, the solution of this problem takes time, so the general solution will time out, because the continuous selection of the interval, resulting in a lot of white to find many times the solution of repetition. So we use the prefix and the tricks. For example, the following number: A1,A2,..., ai,..., an a 1, a 2, ..., a I, ..., a n a_1,a_2,..., a_i,..., a_n; If we use it, we calculate the solution of each AI a I a_i di d i D_i, then we define SI s i s_i for ∑ik=1di∑k = 1 i d i \sum_{k=1}^{i}{d_i} so any interval segment and we can use the difference of S to express, such as [L,r], equals sr−sl−1

Related Article

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.