Codeforces Round #108 (Div. 2)

A Marks

Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group’s gradebook.

Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.

Let’s consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let’s consider a student successful, if there exists a subject he is the best at.

Your task is to find the number of successful students in the group.

Input

The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of students and the number of subjects, correspondingly. Next n lines each containing m characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.

Output

Print the single number — the number of successful students in the given group.


反思

这题一开始的时候感觉有点乱,没大读懂题意,之后好好想了想,认真调了一下出来啦!

题意

给定我们n个学生和它的m个成绩,我们来判断每一个学生在每一科是不是能做到最好的那个,如果做到过,他就是成功的学生

问一共有多少个学生

实现

我们对每一个科进行统计,看看每一科最大值是几,如果某个学生的这科成绩和最大值相等那他一定就是成功的

Code

// Problem: A - Marks
// Contest: Virtual Judge - Codeforces Beta Round #108 (Div2)
// URL: https://vjudge.net/contest/440155#problem/A
// Memory Limit: 262 MB
// Time Limit: 1000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int n, m;

int a[110][110];
int maxx[110];

int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		char c[110];
		scanf("%s",c + 1);
		for(int j = 1; j <= m; j++){
			a[i][j] = c[j] - '0';
			// maxx[j] = max(maxx[j], a[i][j]);
		}
	}
	
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++){
			maxx[i] = max(maxx[i], a[j][i]);
		}
	}
	
	// for(int i = 1; i <= m; i++){
		// // for(int j = 1; j <= n; j++){
			// cout << maxx[i] << " ";
		// // }
		// // cout << endl;
	// }
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(maxx[j] == a[i][j]){
				ans++;
				break;
			}
		}
	}
	cout << ans;
	re 0;
}

单词

correspondingly 相应的

dean 院长,系主任

B Steps

One day Vasya went out for a walk in the yard but there weren’t any of his friends outside and he had no one to play touch and run. But the boy didn’t lose the high spirits and decided to play touch and run with himself. You may ask: “How did he do that?” The answer is simple.

Vasya noticed that the yard is a rectangular n × m field. The squares have coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m), where x is the index of the row and y is the index of the column.

Initially Vasya stands in the square with coordinates (xc, yc). To play, he has got a list of k vectors (dxi, dyi) of non-zero length. The game goes like this. The boy considers all vectors in the order from 1 to k, and consecutively chooses each vector as the current one. After the boy has chosen a current vector, he makes the maximally possible number of valid steps in the vector’s direction (it is possible that he makes zero steps).

A step is defined as one movement from the square where the boy is standing now, in the direction of the current vector. That is, if Vasya is positioned in square (x, y), and the current vector is (dx, dy), one step moves Vasya to square (x + dx, y + dy). A step is considered valid, if the boy does not go out of the yard if he performs the step.

Vasya stepped on and on, on and on until he ran out of vectors in his list. Ha had been stepping for so long that he completely forgot how many steps he had made. Help the boy and count how many steps he had made.

Input

The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard’s sizes. The second line contains integers xc and yc — the initial square’s coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m).

The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two integers dxi and dyi (|dxi|, |dyi| ≤ 109, |dx| + |dy| ≥ 1).

Output

Print the single number — the number of steps Vasya had made.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.


反思

在代码复制的时候,很多地方都复制错了,感觉分类有点多,也没仔细顺一下,最后找了队友小黄鸭才debug出来

题意

我们要根据一个向量来尽可能的往边界上走,没按照这个向量走一次就算成功走一步,问一共可以走几步

实现

分情况讨论,要注意变化向量可能为0的情况,因为不能除0模0

Code

// Problem: B - Steps
// Contest: Virtual Judge - Codeforces Beta Round #108 (Div2)
// URL: https://vjudge.net/contest/440155#problem/B
// Memory Limit: 262 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int n, m;
int xc, yc;
int k;

int main(){
	cin >> n >> m;
	cin >> xc >> yc; // start
	ll ans = 0;
	
	int dx, dy;
	
	cin >> k;
	while(k--){
		cin >> dx >> dy;
        if(dx == 0 && dy != 0){ // x = 0
            if(dy > 0){
                ans += (m - yc) / dy;
                yc += (m - yc) / dy * dy;
            }
            else{
                dy = -dy;
                if(yc % dy == 0){
                    ans += yc / dy - 1;
                    yc = yc % dy + dy;
                }
                else{
                    ans += yc / dy;
                    yc = yc % dy;
			    }
            }
        }
        else if(dx != 0 && dy == 0){
            if(dx > 0){
                ans += (n - xc) / dx;
                xc += (n - xc) / dx * dx;
            }
            else{
                dx = -dx;
                if(xc % dx == 0){
                    ans += xc / dx - 1;
                    xc = xc % dx + dx;
                }
                else{
                    ans += xc / dx;
                    xc = xc % dx;
			    }
            }
        }
        else{
            if(dx > 0 && dy > 0){
                ans += min((n - xc) / dx, (m - yc) / dy);
                int t = min((n - xc) / dx, (m - yc) / dy);
                xc += t * dx;
                yc += t * dy;
            }
            if(dx >= 0 && dy < 0){
                dy = -dy;
                if(yc % dy == 0){
                	int t = min((n - xc) / dx, yc / dy - 1);
                    ans += t;
                    xc += t * dx;
                    yc = yc - t * dy;
                }
                else{
                	int t = min((n - xc) / dx, yc / dy); 
                    ans += t;
                    xc += t * dx;
                    yc = yc - t * dy;
                }
            }
            if(dx < 0 && dy >= 0){
                dx = -dx;
                if(xc % dx == 0){
                	int t = min((m - yc) / dy, xc / dx - 1);
                    ans += t;
                    xc = xc - t * dx;
                    yc += t * dy;
                }
                else{
                	int t = min((m - yc) / dy, xc / dx);
                    ans += t;
                    xc = xc - t * dx;
                    yc += t * dy;
                }
                
            }
            if(dx < 0 && dy < 0){
                int x;
                int y; // step
                dx = -dx;
                dy = -dy;
                if(xc % dx == 0){
                    x = xc / dx - 1;
                    // xc = xc % dx + dx;
                }
                else{
                    x = xc / dx;
                    // xc = xc % dx;
                }
                if(yc % dy == 0){
                    y = yc / dy - 1;
                    // yc = yc % dy + dy;
                }
                else{
                    y = yc / dy;
                    // yc = yc % dy;
                }
                xc = xc - dx * min(x, y);
                yc = yc - dy * min(x, y);
                ans += min(x, y);
            }
        }
	}
	cout << ans << endl;
}

C Pocket Book

One day little Vasya found mom’s pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let’s number the names from 1 to n in the order in which they are written.

As mom wasn’t home, Vasya decided to play with names: he chose three integers i, j, k (1 ≤ i < j ≤ n, 1 ≤ k ≤ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names “CBDAD” and “AABRD” and swap their prefixes with the length of 3, the result will be names “AABAD” and “CBDRD”.

You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).

Input

The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.

Output

Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 ( 1 0 9 10^9 109 + 7).

反思

读题读题读题!

题意

这个小孩把任意两个的任意前缀给换了任意次,问我们原来可能有多少个名字

实现

因为这个小孩可以选择任意前缀,而且可以换任意次,所以说他实际上能做到对每个对应位置的字符都可以进行交换,所以说,能得到的单词就是每一位不同的字母个数的乘积

Code

// Problem: C. Pocket Book
// Contest: Codeforces - Codeforces Round #108 (Div. 2)
// URL: https://codeforces.com/contest/152/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

// 有点杂乱,建议

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int n, m;
char s[110][110];
int pre[128];
int cnt[110]; // 每列不同的字符有多少个

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		scanf("%s", s[i]);
	}
	
	for(int j = 0; j < m; j++){
		memset(pre, 0, sizeof(pre));
		for(int i = 0; i < n; i++){
			if(!pre[s[i][j]]){
				pre[s[i][j]]++;
				cnt[j]++;
			}
		}
	}
	
	int ans = 1;
	
	for(int i = 0; i < m; i++){
		ans = (ll)(ans % 1000000007 * (cnt[i] % 1000000007)) % 1000000007;
	}
	
	cout << ans;
	
	re 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值