我是靠谱客的博主 可靠山水,最近开发中收集的这篇文章主要介绍2021.1.14寒假打卡Day11C - 1-SATD - BrickE - Blocks on GridF - Unlucky 7,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

C - 1-SAT

Problem Statement
Given are N strings S1,S2,…,SN. Each of these is a non-empty string consisting of lowercase English letters, with zero or one ! added at the beginning.

We say a string T to be unsatisfied when it matches one of S1,S2,…,SN regardless of whether we add an ! at the beginning of T.

Determine whether there exists an unsatisfied string. If so, present one such string.

Constraints
1 ≤ N ≤ 2×105
1 ≤ |Si| ≤ 10
Si is a non-empty string consisting of lowercase English letters, with zero or one ! added at the beginning.

Input
Input is given from Standard Input in the following format:
N
S1

SN

Output
If there exists an unsatisfied string, print one such string.
If there is no unsatisfied string, print satisfiable.

Sample Input 1

6
a
!a
b
!c
d
!d

Sample Output 1

a

a matches S1 as is, and it matches S2 when we add an !, so it is unsatisfied. Besides that, d will also be accepted.

Sample Input 2

10
red
red
red
!orange
yellow
!blue
cyan
!green
brown
!gray

Sample Output 2

satisfiable

学习新东西——哈希表 (附本题题解)

用30进制计算字母字符串的哈希值,利用哈希表查询是否有不满足的值

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

string s[200005];

int main() {
    int n;
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>s[i];
    }
	map<long long, int> mp;
    //处理正常的字符串
    for (int i=1; i<=n; i++) {
        if ('!'==s[i][0]) continue;
        long long x=0;
        for (int j=0; j<(int)s[i].length(); j++)
            x = x*30+(s[i][j]-'a');
        mp[x]=i;
    }
    //处理'!'开头的字符串
    for (int i=1; i<=n; i++) {
        if ('!'!=s[i][0]) continue;
        long long x=0;
        for (int j=1; j<(int)s[i].length(); j++) 
            x = x*30+(s[i][j]-'a');
        if (mp.count(x)) {
            cout<<s[mp[x]]<<"n";
            return 0;
        }
    }
    cout<<"satisfiablen";
    return 0;
}

哈希果然还是没看懂

D - Brick

We have a truck, which can carry at most N kilograms.

We will load bricks onto this truck, each of which weighs W kilograms. At most how many bricks can be loaded?

Constraints
1 ≤ N,W ≤ 1000
N and W are integers.

Input
Input is given from Standard Input in the following format:
N W

Output
Print an integer representing the maximum number of bricks that can be loaded onto the truck.

Sample Input 1

10 3

Sample Output 1

3

Each brick weighs 3 kilograms, so 3 bricks weigh 9 kilograms, and 4 weigh 12 kilograms.
Thus, we can load at most 3 bricks onto the truck that can carry at most 10 kilograms.

Sample Input 2

1000 1

Sample Output 2

1000

整除即可,略

E - Blocks on Grid

We have a grid with H horizontal rows and W vertical columns. The square at the i-th row from the top and j-th column from the left has Ai,j blocks stacked on it.

At least how many blocks must be removed to make all squares have the same number of blocks?

Constraints
1≤H,W≤100
0≤Ai,j≤100

Input
Input is given from Standard Input in the following format:
H W
A1,1 A1,2 … A1,W

AH,1 AH,2 … AH,W

Output
Print the minimum number of blocks that must be removed.

Sample Input 1

2 3
2 2 3
3 2 2

Sample Output 1

2

Removing 1 block from the top-right square and 1 from the bottom-left square makes all squares have 2 blocks.

Sample Input 2

3 3
99 99 99
99 0 99
99 99 99

Sample Output 2

792

Sample Input 3

3 2
4 4
4 4
4 4

Sample Output 3

0
#include<iostream>
using namespace std;

int main(){
	int a[105][105];
	int h,w,min=100,ans=0;
	cin>>h>>w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			cin>>a[i][j];
			min=min<a[i][j]?min:a[i][j];
	}
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			ans+=a[i][j]-min;
	}
	cout<<ans;
	return 0;
} 

F - Unlucky 7

Problem Statement
Takahashi hates the number 7.

We are interested in integers without the digit 7 in both decimal and octal. How many such integers are there between 1 and N (inclusive)?

Constraints
1≤N≤105
N is an integer.

Input
Input is given from Standard Input in the following format:
N

Output
Print an integer representing the answer.

Sample Input 1

20

Sample Output 1

17

Among the integers between 1 and 20, 7 and 17 contain the digit 7 in decimal. Additionally, 7 and 15 contain the digit 7 in octal.
Thus, the 17 integers other than 7, 15, and 17 meet the requirement.

Sample Input 2

100000

Sample Output 2

30555

统计十进制n以内(包括n)十进制和八进制不带7的数

#include<iostream>
using namespace std;

int iswith7(int x){
	int d=x,o=x;
	while(d!=0){
		if(d%10==7) return 1;
		d/=10;
	}
	while(o!=0){
		if(o%8==7) return 1;
		o/=8;
	}
	return 0;
}

int main(){
	int n,ans=0;
	cin>>n;
	ans=n;
	for(int i=1;i<=n;i++)
		if(iswith7) --ans;
	cout<<ans;
	return 0;
} 

最后

以上就是可靠山水为你收集整理的2021.1.14寒假打卡Day11C - 1-SATD - BrickE - Blocks on GridF - Unlucky 7的全部内容,希望文章能够帮你解决2021.1.14寒假打卡Day11C - 1-SATD - BrickE - Blocks on GridF - Unlucky 7所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部