eg:感覺題目很簡單,但是下午有課,打了倆小時多就去上課了,最後七題結尾。
比賽傳送門
A-Find the twins
題意:找出十個數裏是否有17和18
題解:簽到
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
int a[11];
int main(){
int T;
scanf("%d",&T);
while(T--){
int zack=0,mack=0;
for(int i=1;i<=10;i++){
scanf("%d",&a[i]);
if(a[i]==17)zack=1;
if(a[i]==18)mack=1;
}
for(int i=1;i<10;i++)printf("%d ",a[i]);
printf("%d\n",a[10]);
if(zack && mack)puts("both");
else if(zack)puts("zack");
else if(mack)puts("mack");
else puts("none");
printf("\n");
}
return 0;
}
B-Medal Ranking
題意:給出兩個國家的金牌,銀牌,銅牌數量。有兩種排序方法,第一種是獎牌的總數,第二種是每個牌的數量按照優先級比較。
看A國家是否都能贏B國家。
題解:簽到題
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
struct arr{
int sum,no,g,s,m;
}a[3];
int main(){
int T;
scanf("%d",&T);
while(T--){
int count=0,color=0;
for(int i=1;i<=2;i++){
scanf("%d%d%d",&a[i].g,&a[i].s,&a[i].m);
a[i].sum=a[i].g+a[i].s+a[i].m;a[i].no=i;
}
printf("%d %d %d %d %d %d\n",a[1].g,a[1].s,a[1].m,a[2].g,a[2].s,a[2].m);
if(a[1].sum>a[2].sum)count=1;
if(a[1].g>a[2].g)color=1;
else if(a[1].g==a[2].g){
if(a[1].s>a[2].s)color=1;
else if(a[1].s==a[2].s){
if(a[1].m>a[2].m)color=1;
}
}
if(count && color)puts("both");
else if(count)puts("count");
else if(color)puts("color");
else puts("none");
puts("");
}
return 0;
}
C-Brownies vs. Candies vs. Cookies
題意:給出n組人和m個餅乾,若m個餅乾小於等於當前的人,那麼m可以翻倍。
題解:模擬即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
int n,m,k,x;
int main(){
int T;
scanf("%d",&T);
for(int ttt=1;ttt<=T;ttt++){
scanf("%d%d",&n,&m);
printf("Practice #%d: %d %d\n",ttt,n,m);
scanf("%d",&k);
for(int i=1;i<=k;i++){
scanf("%d",&x);
if(m>x)printf("%d %d\n",x,m-x),m-=x;
else {
while(m<=x)m*=2;
printf("%d %d\n",x,m-x),m-=x;
}
}
puts("");
}
return 0;
}
D-Lemonade Stand
題意:做一杯奶茶需要x個檸檬和y份糖,經營n天,每天需要做ai份奶茶,當天一個檸檬的價格是bi,80份糖的價格是ci,只能80份80份的買糖。
題解:貪心,如果在第i天檸檬不夠了,那麼一直買到第j天的需要,保證bj<bi。糖同理,但是糖複雜一點判斷一下即可。
#include<bits/stdc++.h>
using namespace std;
struct day{
int num;
int pl;
int ps;
}a[1005];
priority_queue<int, vector<int>, greater<int> >q1,q2;
int main(){
int k,n,t,su=0,ple,psu,pl,ps;
cin>>n;
while(n--){
while(!q1.empty())q1.pop();
while(!q2.empty())q2.pop();
su=0;
cin>>k>>ple>>psu;
long long ans=0;
for(int i=0;i<k;i++){
scanf("%d%d%d",&a[i].num,&a[i].pl,&a[i].ps);
}
for(int i=0;i<k;i++){
q1.push(a[i].pl);
ans=ans+q1.top()*a[i].num*ple;
}
for(int i=0;i<k;i++){
q2.push(a[i].ps);
if(a[i].num*psu>su){
int ff;
if((a[i].num*psu-su)%80==0)ff=(a[i].num*psu-su)/80;else ff=(a[i].num*psu-su)/80+1;
ans=ans+q2.top()*ff;
su=ff*80-(a[i].num*psu-su);
}
else su=su-a[i].num*psu;
}
cout<<ans<<endl;
}
return 0;
}
E-Rain Gauge
題意:算出同心的圓和正方形的面積交
題解:幾何題,三種情況分類討論即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double mPI=3.14159265358979;
ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
double s,r;
double solve(){
if(2*r*r>=s*s)return s*s;
if(s>=2*r)return mPI*r*r;
double d=s/2;
double s1=sqrt(r*r-d*d)*d;
double s2=r*r/2*(mPI/2-2*acos(d/r));
return (s1+s2)*4;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%lf%lf",&s,&r);
printf("%.2lf\n",solve());
}
return 0;
}
F-Balanced Strings
題意:給出平衡字符串的定義:任意偶數長度的連續子串的元音字母和輔音字母個數相同。現在各出一個只含小寫字母和?的字符串,?可以安排任意字母,問有多少種方法使得其爲一個平衡字符串。
題解:統一考慮整個字符串,假設第一個爲元音,那麼第一個?就有20種,之後類推。假設第一個爲輔音,那麼第一個?爲元音,之後類推。最後答案爲兩種之和。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
char s[maxn];
int main(){
int T,ttt=0;
scanf("%d",&T);
while(T--){
ttt++;
ll ans=0;
scanf("%s",&s);
int len=strlen(s);
for(int j=0;j<2;j++){
ll sum=1;
for(int i=0;i<len;i++){
int flag=0;
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='y')flag=1;
if((i+j)%2){
if(s[i]=='?')sum*=20;
else if(flag)sum=0;
}else {
if(s[i]=='?')sum*=6;
else if(!flag)sum=0;
}
}
ans+=sum;
}
printf("String #%d: %lld\n",ttt,ans);
puts("");
}
return 0;
}
G-Towers of Hanoi Grid
題意:二維漢諾塔,問最少步數。
題解:一個盤子的最少步數爲,n個盤子就是,不成立的情況就是
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll read(){
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
int n,m;
int main(){
int T,ttt=0;
scanf("%d",&T);
while(T--){
ttt++;
scanf("%d%d",&n,&m);
printf("Grid #%d: ",ttt);
if(n>(m-1)*(m-1)+1)puts("impossible");
else{
printf("%d\n",n*2*(m-1));
}
puts("");
}
return 0;
}