当前位置:网站首页>[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;
}
边栏推荐
- YouTube "label products" pilot project launched
- The difference between delete, truncate and drop in MySQL
- 2019 Hangdian multi school first 6581 vacation [thinking]
- [training Day6] triangle [mathematics] [violence]
- Read the registry through the ATL library clegkey (simple and convenient)
- Solve the problem that gd32f207 serial port can receive but send 00
- PD user manual
- English translation Chinese common dirty words
- Codeforces round 580 (Div. 2) c- almost equal [Law]
- Sql164 next day retention rate of new users per day in November 2021
猜你喜欢

"Hualiu is the top stream"? Share your idea of yyds

Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)

Choose the appropriate container runtime for kubernetes

Batch download files from the server to the local

Install MySQL 5.7.37 on windows10

Leetcode 146: LRU cache

Bypass using the upper limit of the maximum number of regular backtracking

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用

C# 窗体应用TreeView控件使用

Description of large and small end mode
随机推荐
Solutions to oom caused by pictures in res directory
Hide the middle digit of ID number
Covid-19-20 - basic method of network segmentation based on vnet3d
English translation Chinese common dirty words
Unit DLU of resource editor
Sword finger offer 48. the longest substring without repeated characters
Use of paging assistant PageHelper
Sword finger offer 50. the first character that appears only once
Istio II traffic hijacking process
How to use the interface control telerik UI for WinForms development step progress bar?
Home Assistant中接入博联WiFi智能遥控
Solve the problem that gd32f207 serial port can receive but send 00
01 | opening words: teach you to build a blog website hand in hand
871. Sum of divisors
从码农转型大音乐家,你只差这些音乐处理工具
Click the button to return to the top smoothly
"Hualiu is the top stream"? Share your idea of yyds
Functional test of redisgraph multi active design scheme
Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket
Hcip early summary