B. Painting Pebbles1

// Problem: B. Painting Pebbles
// Contest: Codeforces - Codeforces Round #289 (Div. 2, ACM ICPC Rules)
// URL: https://codeforces.com/problemset/problem/509/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 2022-03-20 17:09:29
// 
// Powered by CP Editor (https://cpeditor.org)

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

#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define mp make_pair

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        

const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const double pi  = acos(-1.0);

inline ll qmi (ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * a%mod;
		a = a * a %mod;
		b >>= 1;
	}
	return ans;
}
inline int read () {
	int x = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f?-x:x;
}
template<typename T> void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) print(x/10);
	putchar(x % 10 + '0');
}
inline ll sub (ll a, ll b) {
	return ((a - b ) %mod + mod) %mod;
}
inline ll add (ll a, ll b) {
	return (a + b) %mod;
}
inline ll inv (ll a) {
	return qmi(a, mod - 2);
}
vector<int> a, col[110];
void solve() {
	int n, k;
	cin >> n >> k;
	
	int b[110][110] = {0};
	for (int i = 0; i < n; i ++) {
		int x;
		cin >> x;
		a.pb(x);
		int c = 1;
		
		for (int j = 0; j < a[i]; j ++) {
			col[i].pb(c);
			c ++;
			if (c > k) c = 1;
		}
		for (int j = 0; j < col[i].size(); j ++) {
			b[i][col[i][j]] ++;
		}
	}
	for (int i =  0; i < n; i ++) {
		for (int j = 0; j < n; j ++) {
			for (int m = 1; m <= k; m ++) {
				if (abs(b[i][m] - b[j][m]) > 1) {
					puts("NO");
					return;
				}
			}
		}
	}
	puts("YES");
	for (int i = 0; i < n; i ++) {
		for (auto t: col[i]) {
			cout << t<< ' ';
		}
		puts("");
	}
	
}
int main () {
	// ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
    int t;
    t =1;
    //cin >> t;
    while (t --) solve();
    return 0;
}



题意:给定n,k,(i, j) b[i][k] - b[j][k] <= 1

题解:按照1 2 3 4 周期性构造就行了

Sure! Here's an implementation of the Pet, Dog, and Rock classes with the requested functions: ```python class Pet: def __init__(self, name, age, weight): self.name = name self.age = age self.weight = weight def getName(self): return self.name def getAge(self): return self.age def getWeight(self): return self.weight def setName(self, name): self.name = name def setAge(self, age): self.age = age def setWeight(self, weight): self.weight = weight def getLifespan(self): return "unknown lifespan" class Dog(Pet): def __init__(self, name, age, weight, breed): super().__init__(name, age, weight) self.breed = breed def getBreed(self): return self.breed def setBreed(self, breed): self.breed = breed def getLifespan(self): if self.weight > 100: return "Approximately 7 years" else: return "Approximately 13 years" class Rock(Pet): def getLifespan(self): return "Thousands of years" ``` And here's a test program that creates instances of Pet, Dog, and Rock and exercises their inherited and redefined functions: ```python # create some pets and dogs pet1 = Pet("Fluffy", 3, 10) pet2 = Pet("Spike", 5, 20) dog1 = Dog("Rex", 2, 120, "German Shepherd") dog2 = Dog("Fido", 8, 50, "Labrador Retriever") # test the Pet class functions print(pet1.getName()) # Fluffy print(pet1.getAge()) # 3 print(pet1.getWeight()) # 10 pet1.setWeight(15) print(pet1.getWeight()) # 15 print(pet1.getLifespan()) # unknown lifespan # test the Dog class functions print(dog1.getName()) # Rex print(dog1.getBreed()) # German Shepherd print(dog1.getLifespan()) # Approximately 7 years print(dog2.getLifespan()) # Approximately 13 years # test the Rock class functions rock1 = Rock("Pebbles", 1000000, 1) print(rock1.getLifespan()) # Thousands of years ``` I hope this helps! Let me know if you have any other questions.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值