2021 ICPC Asia Taipei Regional(Gym - 103443A)补题

A - Ice Cream

点击查看题目

Problem Description
To celebrate the 3rd anniversary of the Ice Cream Professional Company (ICPC), the company
has an anniversary sale activity. The activity's name is \Buy 𝑋 units and Get 𝑌 units free".
The contents of the activity is as below. First, you will be asking to draw a lottery ticket of
𝑋 units and a lottery ticket of 𝑌 units, and then you can enjoy the discount of buy 𝑋 units
and get 𝑌 units free. It means for every 𝑋 units of ice cream you bought, you will get 𝑌 units
free ice cream. The price of every unit of the ice cream is 3 dollars, and you want to buy some
units of ice cream. Please write a program to calculate the minimum price of your order.
Input Format
The rst line contains an integer 𝑇, which represents the number of test cases. Each test case
contains a single line with 3 integers 𝑋, 𝑌 , 𝑁, which represents the lottery tickets of 𝑋, 𝑌 ,
and you want to obtain at least 𝑁 ice cream. Any two consecutive integers are separated by
exactly one space.
Output Format
For each test case outputs an integer, which represents the minimum price of your order.
Technical Specification
∙ 1 ≤ 𝑇 ≤ 15
∙ 1 ≤ 𝑋, 𝑌 ≤ 1, 000
∙ 1 ≤ 𝑁 ≤ 15, 000

代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
     int t;cin>>t;
     for(int i=0;i<t;i++){
         int a;cin>>a;
         int b; cin>>b;
         int cnt=a+b;
         int n;cin>>n;
          int ans=0;
          int ans2=0;
         if(n>cnt){
            ans+= n/cnt;
            n=n%cnt;
         }
        int cnt1=n*3;
         int cnt2=a*3;
         ans2=min(cnt1,cnt2);
         cout<<a*ans*3+ans2<<endl;
     }
    return 0;
}

B - Maximum Sub-Reverse Matching

点击查看题目

Consider two strings of the same length, for example, 𝑠1 = "happycoding" and 𝑠2 = "onedocument".
Comparison 𝑠1 and 𝑠2 character by character, they get 2 matches, such as
happycoding
onedocument
00000100010
Suppose that 𝑠′
2 is obtained by reversing the substring from the 4𝑡ℎ character to the 8𝑡ℎ character
of 𝑠2, i.e.,
𝑠′
2 = "onemucodent". Then, 𝑠1 and 𝑠′
2 will get 4 matches, such as
happycoding
onemucodent
00000111010
Given a pair of two strings of the same length, say 𝑠1 and 𝑠2, your task is to reverse a substring
of 𝑠2 so that the resulting number of characters matched by position can be maximized.
Input Format
The rst line contains an integer 𝑇, which represents the number of test cases. Each test case
below contains three lines. For each test case, the rst line is an integer 𝑛 ≤ 1, 000, which
represents the length of the next two lines of strings, and the next two lines are two lowercase
strings of length 𝑛, called 𝑠1 and 𝑠2 respectively.
Output Format
Each test case outputs four integers 𝑚1,2,𝑚1,2, 𝑎, 𝑏, separated by a space. The rst integer
𝑚1,2 is the number of characters that 𝑠1 and 𝑠2 match by position. The second integer 𝑚1,2
is
the maximum possible number of matches by matching 𝑠1 and the substring reversed version
of 𝑠2. 𝑎 ≤ 𝑏 are the indexes of 𝑠2, starting from 1. By reversing the substring indexed from 𝑎
to 𝑏 in 𝑠2, the maximum number of matches will be obtained. If there are multiple solutions,
output the one with the smallest value of 𝑏−𝑎. If multiple solutions are still obtained, the one
with the minimum value of 𝑎 is output.
Technical Specification
∙ 1 ≤ 𝑇 ≤ 50.
∙ 1 ≤ 𝑛 ≤ 1, 000
∙ All string characters are lowercase letters.

代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t; cin>>t;
    while(t--){
        int n;cin>>n;
        char a[1100]; cin>>a;
        char b[1100];  cin>>b;
        int ans1=0;
        for(int i=0;i<n;i++){
            if(a[i]==b[i])ans1++;
        }
        int ans2=ans1;
        int l=1;int r=1;
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                int cnt=0;

                for(int k=0;k<i;k++){
                    if(a[k]==b[k]) cnt++ ;
                }
                for(int k=j,o=i;k>=i;k--,o++){
                    if(a[o]==b[k]) cnt++ ;
                }
                for(int k=j+1;k<n;k++){
                    if(a[k]==b[k]) cnt++;
                }
                if(cnt>ans2){
                    ans2=cnt;
                    l=i+1;
                    r=j+1;
                }else 
                if(cnt==ans2){
                    if(j-i<r-l){
                         ans2=cnt;
                    l=i+1;
                    r=j+1;
                    }
                }
            }
        }
        cout<<ans1<<" "<<ans2<<" "<<l<<" "<<r<<endl;
    }
    return 0;
}

M - Escaping the Foggy Forest

点击查看题目 Problem Description Nobi is walking in a foggy forest. He tries to locate himself using a map. The forest is divided using vertical and horizontal lines into 𝑚 × 𝑛 regions so the map is represented by an 𝑚 by 𝑛 matrix, with rows indexed from 0 to 𝑚−1 and columns indexed from 0 to 𝑛−1. Each entry of the matrix corresponds to a region of the forest, where the entry with row index 𝑟 and column index 𝑐 is denoted by 𝑀(𝑟, 𝑐). Each entry is either 1 or 0. A 1 indicates that there are very tall trees in the region, and a 0 indicates that the region contains only bushes. It is known that the outside of the forest is surrounded by bushes, which means that regions not speci ed in the map are treated as 0s. Nobi wants to know which region he might be in. Because the fog is heavy, Nobi can only observe the region he stays in, the region in the front, and the region on the right side. However, he does not know which direction he faces to. Please help Nobi to nd the possible regions he is in, assuming that there are only four directions, \N", \E", \S", and \W". For example, below is a 2 by 3 matrix. Nobi observes that there are tall trees in the regions he stays in and in front of him (cor- responding to matrix entries of 1), and the region on the right side of him has only bushes (corresponding to a matrix entry of 0). It is possible that Nobi is in the region corresponding to entry 𝑀(0, 0) because 𝑀(0, 0) = 1, and when he faces to the direction \E", the entry in front of him, 𝑀(0, 1), is 1; the entry on the right side of him, 𝑀(1, 0), is 0. The other possible region is 𝑀(0, 1) because 𝑀(0, 1) = 1 and when he faces to \W", the entries in the front is 𝑀(0, 0) = 1; the entry on the right side is outside the map, which is treated as 0. Input Format The rst line of a test case contains two integers 𝑚 and 𝑛, which are the numbers of rows and columns of the matrix, respectively. The rows of the matrix are indexed from 0 to 𝑚 − 1, and columns are indexed from 0 to 𝑛−1. The following 𝑚 lines are the content of the map. Each of the 𝑚 lines contains 𝑛 integers. The last line contains three integers 𝑠, 𝑓, and 𝑟. The number 𝑠, 𝑓, and 𝑟 indicate what Nobi observes in the regions he stays in, in front of him, and on the right side of him, respectively. Output Format Each line of the output contains two integers, which are the possible row and column indices of the region Nobi is in, respectively. It is guaranteed that Nobi is in the forest. If there are more than one possible regions, output the regions with smaller row index rst; for regions with the same row index, output the one with smaller column index rst. Technical Specification ∙ 1 ≤ 𝑚, 𝑛 ≤ 100 ∙ Each entry is either 0 or 1. ∙ 𝑠, 𝑓, 𝑟 ∈ {0, 1}

代码

#include <bits/stdc++.h>
using namespace std;
int a[110][110];
bool cmp(pair <int,int> a,pair <int,int> b){
    if(a.first==b.first) return a.second<b.second;
    return a.first<b.first;
}
int main()
{
    memset(a,0,sizeof a);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    int s;cin>>s;
    int f; cin>>f;
    int r; cin>>r;
    set<pair<int ,int> > vec;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]==s){
                if(a[i-1][j]==f&&a[i][j+1]==r)
                {
                    pair<int,int> tt;
                    tt.first=i;
                    tt.second=j;
                   vec.insert(tt);
                }
                if(a[i][j+1]==f&&a[i+1][j]==r)
                {
                    pair<int,int> tt;
                    tt.first=i;
                    tt.second=j;
                   vec.insert(tt);
                }
                 if(a[i+1][j]==f&&a[i][j-1]==r)
                {
                    pair<int,int> tt;
                    tt.first=i;
                    tt.second=j;
                   vec.insert(tt);
                }
                 if(a[i][j-1]==f&&a[i-1][j]==r)
                {
                    pair<int,int> tt;
                    tt.first=i;
                    tt.second=j;
                   vec.insert(tt);
                }
            }
        }
    }
    for(pair<int,int> t: vec){
        cout<<t.first-1<<" "<<t.second-1<<endl;
    }
    
    return 0;
}
posted @ 2021-12-17 19:33  kingwzun  阅读(621)  评论(0编辑  收藏  举报