当前位置:网站首页>[training Day10] silly [simulation] [greed]
[training Day10] silly [simulation] [greed]
2022-07-24 20:10:00 【VL——MOESR】

Ideas :
We found that its ratio is the original string w and b The number ratio of .
Let's just simulate it paragraph by paragraph .
c o d e code code
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
const ll MAXN = 1e5 + 10;
ll t, n;
struct node {
char ch;
ll x;
}a[MAXN];
ll gcd(ll x, ll y) {
if(y == 0) return x;
else return gcd(y, x % y);
}
ll ji(ll x, ll y, ll z) {
return x * z / y;
}
ll sum(ll x, ll y) {
// w b
ll w = 0, b = 0, len = 0;
for(ll i = 1; i <= n; i ++) {
if(a[i].ch == 'B') {
if(w * y % x == 0)
if(b < ji(w, x, y) && b + a[i].x >= ji(w, x, y)) len ++;
b += a[i].x;
}
if(a[i].ch == 'W') {
if(b * x % y == 0)
if(w < ji(b, y, x) && w + a[i].x >= ji(b, y, x)) len ++;
w += a[i].x;
}
}
return len;
}
int main() {
freopen("silly.in", "r", stdin);
freopen("silly.out", "w", stdout);
scanf("%lld", &t);
while(t--) {
scanf("%lld", &n);
ll b = 0, w = 0;
for(ll i = 1; i <= n; i ++) {
scanf("%lld %c", &a[i].x, &a[i].ch);
if(a[i].ch == 'W') w += a[i].x;
else b += a[i].x;
}
if(w == 0) {
printf("%lld\n", b);
continue;
}
if(b == 0) {
printf("%lld\n", w);
continue;
}
ll k = gcd(b, w);
b /= k, w /= k;
ll len = sum(w, b);
printf("%lld\n", len);
}
return 0;
}
边栏推荐
- Data transmission of different fragments in the same activity
- Basic idea of regularization
- [shader realizes the flicker effect of three primary colors of television signal _shader effect Chapter 5]
- Todolist case
- Install MySQL 5.7.37 on windows10
- Implementation of OA office system based on JSP
- 871. Sum of divisors
- 147 set whether to cache by using the routing meta information - use of include and exclude - use of activated and deactivated
- Monotone stack and monotone queue (linear complexity optimization)
- Machine learning job interview summary: five key points that resume should pay attention to
猜你喜欢

Analysis and Simulation of strlen function

Todolist case

Istio II traffic hijacking process

Install MySQL 5.7.37 on windows10

Sword finger offer 52. The first common node of the two linked lists

Leetcode 48 rotating image (horizontal + main diagonal), leetcode 221 maximum square (dynamic programming DP indicates the answer value with ij as the lower right corner), leetcode 240 searching two-d

聊下自己转型测试开发的历程

Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr

Usage and introduction of MySQL binlog

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
随机推荐
Unity2d~ game practice of decrypting Zhou mu (completed in three days)
纯C实现----------尼科彻斯定理
Redis common configuration description
Ask a question: is there an error msg = ora-04036: instance usage when using CDC to monitor oracle
vlan技术
The U.S. economy continues to be weak, and Microsoft has frozen recruitment: the cloud business and security software departments have become the hardest hit
Istio二之流量劫持过程
2019 Hangzhou Electric Multi School Game 9 6684 Rikka with game [game question]
Hook 32-bit function using the method modified to JMP instruction
Login Huawei device in SSH mode
C# 窗体应用TreeView控件使用
The beginning of winter in the year of bitterness and ugliness
Qt| control qscrollbar display position
【LeetCode】1184. 公交站间的距离
Work notes - some problems encountered when using jest
Usage and introduction of MySQL binlog
Apache atlas version 2.2 installation
Excuse me: is Flink 1.14.5 compatible with MySQL CDC 2.1.0
872. Maximum common divisor
Call Baidu AI open platform to realize image and character recognition