NBUT-2019-ICPC训练赛

只写了几道能写的题,菜是原罪
A
Mental rotation is a difficult thing to master. Mental rotation is the ability to imagine in your mind how an object would look like from a viewer’s side if you were to rotate it in a particular direction. It is something very important for engineers to learn and master, especially if you are required to do engineering drawing. There are many stages to these mental rotation tasks. We will approach a simple rotation task in this problem.

If you are given the following square -

After rotating it to the right once, it will look like the following -

After rotating it to the left once, it will look like the following -

For this problem you will be given an initial square of size n and a list of rotations to perform.

Your task is to output the final representation of the square after performing all the rotation.

Input
The first line of input contains an integer N (1 ≤ N ≤ 1000). and a string containing a combination of ′L′ and ′R′. Where ′L′ means left rotation and ′R′ means right rotation. Length of the string will not exceed 100. Starting from the second line, the following N line each will contain N of the following characters (>, <, ∨, ∧ or .). Empty space is indicated by a ‘.’ (dot).

Output
The output should be N lines, each containing N characters representing the final representation of the square after all the rotation. For ∨ and ∧ use v (small v) and Shift+6 respectively.

Examples
Input
3 R

v>

<^<
Output
^.v
.<
^.v
Input
3 L
v>

<^<
Output
^.v
.<
^.v
Input
3 LL
v>

<^<
Output
v>

<^<

1
水题代码:
模拟就行了。

  #include<iostream>
    using namespace std;
     
    char a[1005][1005], t[1005][1005];
    int n;
    string s;
     
    void L_rotaing()
    {
    	for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    	t[i][j] = a[j][n-1-i];
     
    	for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    	{
    		if(t[i][j] == '>')       a[i][j] = '^';
    		else if(t[i][j] == '<')  a[i][j] = 'v';
    		else if(t[i][j] == 'v')  a[i][j] = '>';
    		else if(t[i][j] == '^')  a[i][j] = '<';
    		else if(t[i][j] == '.')  a[i][j] = '.';
    	}
    	
    }
     
    void R_rotaing()
    {
    	for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    		t[i][j] = a[n-j-1][i];
    	
    	for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    	{
    		if(t[i][j] == '>')       a[i][j] = 'v';
    		else if(t[i][j] == '<')  a[i][j] = '^';
    		else if(t[i][j] == 'v')  a[i][j] = '<';
    		else if(t[i][j] == '^')  a[i][j] = '>';	
    		else if(t[i][j] == '.')  a[i][j] = '.';
    	}
    	
    }
    int main()
    {
    	cin >> n;
    	cin >> s;
    	
    	for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    	cin >> a[i][j];
    	
    	for(int i = 0; i < s.length(); i++)
    	if(s[i] == 'R')	
    		R_rotaing();
    	else 
    		L_rotaing();
    	
    	for(int i = 0; i < n; i++,cout<<endl)
    	for(int j = 0; j < n; j++)
    		cout << a[i][j];
     
    	return 0;
    	
    }

B:Sponge Bob, the famous cartoon character can only wear square shape pants. Squares shape can be described in geometry as having 4 right angles, just like rectangles. But a square is a special case of rectangle where its width and height are the same.

You are given the width and the height of a 4 right angled shape and need to figure out if it is a square or a rectangle for Sponge Bob. He will get all the square ones as his new pants for the coming Eidul Fitri.

Input
The first line contains T, the number of test cases. For each test case there is a line with two integers (1 ≤ w,h ≤ 1,000,000) representing width and height, respectively.

Output
For each test case, print one line consists of ′YES′ (without quotes) if the shape is a square and good for Sponge Bob’s pants, otherwise print ′NO′ (without quotes) if it is a rectangle and not suitable to be Sponge Bob’s pants.

Example
Input
4
9 9
16 30
200 33
547 547
Output
YES
NO
NO
YES
代码:

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t, w, h;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &w, &h);
        printf(w != h ? "NO\n" : "YES\n");
    }
    return 0;
}
C:
Nina from the IT support needs your help with another daily puzzle she faces. She is able to take her lunch break anytime she wants. But because of limited capacity, she only can take S minutes based on the needs that day. Any extra minutes that she is late, she has to pay RM1 to the late jar.

She prepared a list of her favorite restaurants and how long it would take for her to lunch in each restaurant based on experience, (1 ≤ ti ≤ 109 ). She also assigned a value for each of the restaurants that shows how much extra she is willing to pay but still be happy, (1 ≤ fi ≤ 109 ).

For example, if she needs tx minutes to dine in restaurant x which she values RMfx . If tx≤S then she is fully happy and it is as if she saved RMfx.

But if tx>S she would save fx−(tx−S).

Please help her to find the restaurant that she would be happiest in and meanwhile save the most. Also, keep in mind she can choose exactly one restaurant to lunch each day.

Input
The first line contains an integer – D(1≤D≤10) – the number of days.

The second line contains two space-separated integers — N(1≤N≤104) and S(1≤S≤109) — the number of restaurants in Nina’s list and her lunch break time for the day, correspondingly.

Each of the next N lines contains two space-separated integers — fi(1≤fi≤109) and ti (1≤ti≤109) — the characteristics of the ith restaurant.

Output
In a single line print a single integer — the maximum money she is saving/her happiness by day.

Example
Input
2
2 5
3 3
4 5

1 5
1 7
Output
Case #1: 4
Case #2: -1
贪心求最大:
代码:

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
    int t, n, m, kase = 0;
    scanf("%d", &t);
    while (t--) {
        int max_ = -inf;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; i++) {
            int u, v;
            scanf("%d%d", &u, &v);
            if (v <= m)
                max_ = max(max_, u);
            else max_ = max(max_, u - (v - m));
        }
        printf("Case #%d: %d\n", ++kase, max_);
    }
    return 0;
}

E:
The main hall of your residency is open for use by the local community and public. Since it was built on public donations, there is no charge of using it. Every weekend particularly on public holidays there are up to 50 reservations to use it for multiple events with different durations.

You have been assigned by the residents to develop a program in choosing events to get most out of allocation time per weekend and have as short unused time as possible. Program should find the event(s) which fill(s) the allocation time best and print it in the same sequence as appears in the reservation list.

Input
Each test case consist of a single line.

The line starts with two integer T and N which is the time allocated for the hall to be used in the particular weekend and the number of events. The next T integer are the durations of the events (as appear in the reservation list). For example from the first line in sample data: T=5 hours, N, number of events =5, first event lasts for 1 hour, second is 2 hours, third is 3 hours, fourth is 4 hours, and the last one is 5 hours.

The input process will be terminated by a line containing 0.

Output
For each line of input value, in a single line, first, output a list of integers which are the selected events duration and another integer which is the sum of the selected events duration.

If there are multiple possible list of events, events that appear earlier in the list takes priority.

Example
Input
5 5 1 2 3 4 5
10 9 11 9 3 5 8 4 9 3 2
16 8 12 6 11 11 13 1 10 7
13 5 10 12 2 13 10
28 14 18 19 26 15 18 24 7 21 14 25 2 12 9 6
0
Output
1 4 5
3 5 2 10
6 10 16
13 13
19 7 2 28
01背包+记录路径
代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[10005];
bool path[105][10005];
int c[10005],w[10005];
int main()
{
    int N,V;
    while (cin>>V&&V)
    {
    	cin>>N;
        memset(path,0,sizeof(path));
        memset(dp,0,sizeof(dp));
        for (int i = 1;i <= N;++i) {
        	cin>>c[i];
        	w[i]=c[i];
		}
        for (int i = N;i >= 1;--i)
        {
            for (int j = V;j >= c[i];--j)
            {
            	if (dp[j] <= dp[j-c[i]]+w[i])
            	{
            		dp[j] = dp[j-c[i]]+w[i];
            		path[i][j] = 1;
				}
            }
        }
        
        for (int i = 1,j = V;i <= N&&j > 0;i++)
        {
            if (path[i][j])
            {
            	printf("%d ",w[i]);
            	j -= c[i];
			}
        }
        cout<<dp[V]<<endl;
        //puts("");
    }
    return 0;
}

I:
Ethics regarding artificial intelligence (AI) is an important topic at current times. With recent advancement in the field of self-learning algorithms, the scientific community is facing a hard question of how to introduce ethics in software systems. The question of ethics is particularly difficult due to its subjective nature. What is considered ‘right’ by a particular viewpoint is not necessarily considered ‘right’ by every other viewpoint.

The question of ethics in AI agents becomes even more difficult when the agents are faced with ethical dilemmas. Ethical dilemmas are situations when there is no clear answer regarding the best solution to a problem because all possible solutions lead to certain negative impact. For example, if you press a button then 1 person will die and if you do not press the button then 5 persons will die. If these two are the options then which to follow. If the system believes in the philosophy of non-maleficence, doing the least amount of harm, then the system would take the course of pressing the button and let 1 person die instead of 5 people.

This example is a very simplified approach of portraying an ethical dilemma, but in real life, the AI agents would face much more complex and subtle scenarios requiring a proper ethical framework for them to follow.

In this problem, we are dealing with a RoboTaxi that can only go straight (a lucky one). You will be provided with a snapshot of a 3lane road with multiple obstacles in it. You will have to determine whether the RoboTaxi will crash or not within the given snapshot.

Input
The input consists of 3 lines.

A ‘=’ indicates the position of the RoboTaxi.

‘H’ indicates human in the lane.

‘T’ indicates tree in the lane.

‘P’ indicates parked car in the lane.

‘.’ indicates empty space in the lane.

The length of the road will be 10.

Output
Output will be the indicator of the first obstacle that the RoboTaxi crashes into. If no crash occurs then output ‘Youshallpass!!!’.

Examples
Input

=…

Output
You shall pass!!!
Input

=…H

Output
H
Input

=…T

Output
T
Input
…P
=…TH
…P
Output
T
代码:

#include <bits/stdc++.h>
using namespace std;
int main() {
    char str[5][15];
    int sx, sy;
    for (int i = 0; i < 3; i++)
        scanf("%s", str[i]);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 10; j++) {
            if (str[i][j] == '=') {
                sx = i, sy = j;
                break;
            }
        }
    }
    int l = sy + 1;
    while (l < 10) {
        if (str[sx][l] != '.')
            break;
        l++;
    }
    if (l < 10)
        printf("%c\n", str[sx][l]);
    else printf("You shall pass!!!\n");
    return 0;
}

K:
Nina works as an IT support in a software company and always busy. The biggest issue she is facing is that sometimes she misses some deadlines. In their team the time needed to finish each customer request is estimated based on experience, 1≤x≤105. The moment a request is submitted, she has double of the estimated time to respond to the request, 2x. Meaning if the request A was submitted at 12pm and takes 2 hours to finish, she can wait 2 hours and then work on it for 2 hours and still finish the job on time, by 4 pm and the customer would be satisfied.

Sometimes there is not enough capacity and she has to pick up a lot of requests, and it is expected to miss some deadlines. But she needs your help, to see if arrange correctly what are the maximum requests she can finish before their deadlines.

Let’s assume that she has the list of the requests and their deadline immediately as she starts working every day and she doesn’t take any break until she is done with all of them.

Input
The first line contains integer m (1≤m≤20). Number of cases.

The second line contains integer n (1≤n≤105). Number of the requests.

The last line contains n integers ti (1≤ti≤109), separated by spaces. Estimated time each request should be responded so the customer would be happy.

Output
Print the case number and a single number - the maximum number of satisfied customer for each case.

Example
Input
1
5
15 2 1 5 3
Output
Case #1: 4
Note
If she responds to the request with this order 1, 2, 3, 5, 15, the only customer with the request that requires 5 hours wouldn’t be happy.
贪心 给你每个请求的响应时间,求最大满意客户数
代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXM = 105;
int spt[MAXN];
int main() {
    int t, n, cnt, kase = 0;
    scanf("%d", &t);
    while (t--) {
        cnt = 0;
        long long ans = 0;
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d", spt + i);
        sort(spt, spt + n);
        for (int i = 0; i < n; i++) {
            if (ans <= spt[i]) {
                cnt++;
                ans += spt[i];
            }
        }
        printf("Case #%d: %d\n", ++kase, cnt);
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值