Gym - 100543I Bricks 模拟
2017-08-27 11:12
495 查看
题目链接:点击打开链接
题目大意:给你一段序列,要求你将这个序列,分成每一段B和W比率都相等的块,输出分成的块数。
代码参考:@队友 Vectorhr
这个博客好像传不了图片,谁能教教我,我还没搞明白……
AC代码:
题目大意:给你一段序列,要求你将这个序列,分成每一段B和W比率都相等的块,输出分成的块数。
代码参考:@队友 Vectorhr
这个博客好像传不了图片,谁能教教我,我还没搞明白……
AC代码:
/* 2017年8月27日11:10:06 Gym - 100543I AC 加入了快读 速度更快 */ #include <iostream> #include <map> #include <set> #include <string> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <vector> using namespace std; typedef long long ll; const int maxn=1e5+10; ll n,k,tb,tw,nb,nw,sb,sw,ans; void read(int &x) { char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()); x = 0; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; } void read(long long &x) { char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()); x = 0; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; } void read(char &c) { char ch; for (ch = getchar(); ch != 'B' && ch != 'W'; ch = getchar()); c = ch; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } struct node{ int k; char c; }a[maxn]; void solve(){ //tot_b,tot_w tb=tw=0; read(n); // scanf("%I64d",&n); for(int i=1;i<=n;i++){ read(a[i].k); read(a[i].c); // scanf("%I64d %c",&a[i].k,&a[i].c); if(a[i].c=='W') tw+=a[i].k; else if(a[i].c=='B') tb+=a[i].k; } if(!tw||!tb) printf("%I64d\n",tb+tw); else if(gcd(tb,tw)==1) printf("1\n"); else{ ll g=gcd(tb,tw); //ll sb,sw;//simple b w; if(g!=1) sb=tb/g,sw=tw/g; //每一块中的num_b num_w nb=nw=ans=0; for(int i=1;i<=n;i++){ if(a[i].c=='B'){ //核心代码,如果看不懂,把这个化成分数式子来看, if((sb*nw)%sw==0&&(sb*nw)>=sw&&(sb*nw)>=(sw*nb)&&(nb+a[i].k)*sw>=(nw*sb)){ nb=a[i].k-sb*nw/sw+nb; nw=0; ans++; } else{ nb+=a[i].k; } } else if(a[i].c=='W'){ if(sw*nb%sb==0&&sw*nb>=sb&&(sb*nw)<=(sw*nb)&&(nb*sw)<=(sb*(nw+a[i].k))){ nw=a[i].k-sw*nb/sb+nw; nb=0; ans++; } else{ nw+=a[i].k; } } } printf("%I64d\n",ans); } } int main(){ int t; //scanf("%I64d",&t); read(t); while(t--){ solve(); } return 0; }
相关文章推荐
- 【模拟】NEERC15 J Jump (Codeforces GYM 100851)
- codeforces Gym - 101190H——Hard Refactoring (模拟)
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- codeforces Gym - 101190J ——Jenga Boom(模拟)
- Gym - 101196B Foosball Dynasty【模拟】
- Gym 101341M Last Man Standing 模拟|贪心
- C - Bored Judge Gym - 101102C 模拟
- Gym-101505D Rotating Display [模拟]
- codeforces gym 100357 K (表达式 模拟)
- 使用gym库模拟强化学习环境
- Codeforces Gym 101190 (NEERC 2016) H. Hard Refactoring (模拟 + 树状数组)
- GYM-100952-Palindrome Again !!【模拟】
- Gym 100641A Continued Fractions 模拟|签到
- Gym 100507I Traffic Jam in Flower Town (模拟)
- 【模拟】NEERC15 G Generators (Codeforces GYM 100851)
- Gym - 101246A Bencoding【模拟】
- Gym 100962E Elvis Presley (二叉树模拟 + set)
- Gym - 100543D Wheels 模拟|BFS|签到
- Gym - 101667B Connect3 [模拟]
- Codeforces Gym - 101064A Renzo and the lost artifact [模拟退火]