Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
来源:互联网 发布:淘宝商城的商品特色 编辑:程序博客网 时间:2024/06/16 08:24
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.
The first line of input contains single integer n (2 ≤ n ≤ 100) — the number of days.
The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
4FSSF
NO
2SF
YES
10FFFFFFFFFF
NO
10SSFFSFFSFF
YES
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
水题
代码:
#include<bits/stdc++.h>using namespace std;char res[105];int main(){ int n,sf=0,fs=0; cin>>n; cin>>res; for(int i=0;i<n-1;i++) { if(res[i]=='S'&&res[i+1]=='F') sf++; if(res[i]=='F'&&res[i+1]=='S') fs++; } if(sf>fs) printf("YES\n"); else printf("NO\n"); return 0;}
思路:
就是找个规律,只用1和2就能组成所需的答案。
#include<cstdio>int main(){ int a; scanf("%d",&a); printf("%d 2\n1 2\n",a==1?1:(a-1)*2); return 0;}
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.
It is known that the i-th contestant will eat si slices of pizza, and gain ai happiness for each slice of type 1 pizza they eat, and bi happiness for each slice of type 2 pizza they eat. We can order any number of type 1 and type 2 pizzas, but we want to buy the minimum possible number of pizzas for all of the contestants to be able to eat their required number of slices. Given that restriction, what is the maximum possible total happiness that can be achieved?
The first line of input will contain integers N and S (1 ≤ N ≤ 105, 1 ≤ S ≤ 105), the number of contestants and the number of slices per pizza, respectively. N lines follow.
The i-th such line contains integers si, ai, and bi (1 ≤ si ≤ 105, 1 ≤ ai ≤ 105, 1 ≤ bi ≤ 105), the number of slices the i-th contestant will eat, the happiness they will gain from each type 1 slice they eat, and the happiness they will gain from each type 2 slice they eat, respectively.
Print the maximum total happiness that can be achieved.
3 123 5 74 6 75 9 5
84
6 107 4 75 8 812 5 86 11 63 3 75 9 6
314
In the first example, you only need to buy one pizza. If you buy a type 1 pizza, the total happiness will be 3·5 + 4·6 + 5·9 = 84, and if you buy a type 2 pizza, the total happiness will be 3·7 + 4·7 + 5·5 = 74.
题意:
有N个参赛者,需要准备披萨,有两种披萨,每一种披萨都有S片,分配给这些参赛者,每一个参赛者需要吃的披萨数量不定,接下来N行是每一个参赛者的信息,分别是需要吃的片数,吃了第一种获得的幸福感,吃了第二种披萨的幸福感。求用最少的可以满足这些需求的披萨,求出其中最大的幸福值。
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;vector< pair<ll,ll> >a,b;ll n,s,ans,na,nb,ta,tb;signed main(){ll ss,aa,bb;pair<ll,ll>k;scanf("%I64d%I64d",&n,&s);for(int i=1;i<=n;i++){scanf("%lld%lld%lld",&ss,&aa,&bb);if(aa>bb){ans+=ss*aa;na+=ss;k.first=aa-bb;k.second=ss;a.push_back(k);}else{ans+=ss*bb;nb+=ss;k.first=bb-aa;k.second=ss;b.push_back(k);}}cout<<na<<" "<<nb<<endl;na%=s;nb%=s;cout<<ans<<endl;if(na+nb>s){printf("%lld\n",ans);return 0;}sort(a.begin(),a.end());sort(b.begin(),b.end());for(int i=0;na;i++){ta+=min(na,a[i].second)*a[i].first;na-=min(na,a[i].second);cout<<"ta "<<ta<<" "<<"na "<<na<<endl;}for(int i=0;nb;i++){tb+=min(nb,b[i].second)*b[i].first;nb-=min(nb,b[i].second);cout<<"tb "<<tb<<" "<<"nb "<<nb<<endl;}ans-=min(ta,tb);printf("%I64d\n",ans);return 0;}
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces MemSQL start[c]up Round 1
- MemSQL Start[c]UP 2.0 Round 2
- MemSQL Start[c]UP 2.0 - Round 2
- Codeforces Round MemSQL start[c]up Round 1
- CodeForces MemSQL start[c]up Round 1 A题
- codeforces MemSQL Start[c]UP 2.0 - Round 1 A. Eevee
- Codeforces MemSQL Start[c]UP 2.0 - Round 1
- java开发教程-excel文件的读写
- 店铺众筹,胜算几何?
- 哈希表查找概述
- ASC 05 题解
- MFC对话框访问方式
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- .Net面试题中的经典
- Minimum Inversion Number HDU
- 欢迎使用CSDN-markdown编辑器
- SQL--基本数据类型
- 折腾了一天, 我的TMS320C6713 JTAG 终于通了
- 医药采购项目中PL/SQL乱码问题解决
- 为什么开发Android应用配置了SDK还要配置JDK
- 九度OJ题目1109:连通图