A There Are Two Types Of Burgers
传送门
简单的分类讨论而已
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define ll long long using namespace std; const int maxn=1e6+5; int main(){ int t; cin>>t; while(t--){ int b,p,f; cin>>b>>p>>f; int h,c; cin>>h>>c; int con=b/2; if(con<=min(p,f)){//面包少的话 if(h>=c){//牛肉贵,买牛肉 printf("%d\n",con*h); }else{ printf("%d\n",con*c); } }else{//面包够的话 if(h>=c){//牛肉贵,先买牛肉 if(con>=p){//大于牛肉的数,牛肉全卖加鸡肉 if(con>=(p+f)){ printf("%d\n",h*p+f*c); }else{ printf("%d\n",h*p+(con-p)*c); //printf("aa\n"); } }else{//全卖牛肉 printf("%d\n",con*h); //printf("aa\n"); } }else{//先卖鸡肉 if(con>=f){ if(con>=(p+f)){ printf("%d\n",c*f+p*h); //printf("aaa\n"); }else{ printf("%d\n",c*f+(con-f)*h); //printf("aa\n"); } }else{//全卖鸡肉 printf("%d\n",con*c); //printf("aa\n"); } } } } return 0; }
B Square Filling
传送门
从左上角到右下角枚举过去就行了,简单题
#include <iostream> #include <cstdio> using namespace std; int n,m; int a[55][55]; int c[55][55]; int flag=1; int times=0; struct node{ int x,y; }how[2505]; int check(){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(c[i][j]!=a[i][j]){ flag=0; return 0; } } } flag=1; return 1; } void change(int x,int y){ a[x][y]=1; if(x+1<=n&&y<=m)a[x+1][y]=1; if(x<=n&&y+1<=m)a[x][y+1]=1; if(x+1<=n&&y+1<=m)a[x+1][y+1]=1; } int main(){ cin>>n>>m; int sum=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&c[i][j]); if(c[i][j]==0)sum++; } } //while(1){ int over=check(); for(int i=1;i<=n-1;i++){ for(int j=1;j<=m-1;j++){ if(c[i][j]==1&&c[i][j+1]&&c[i+1][j]&&c[i+1][j+1]){ change(i,j); how[times].x=i,how[times++].y=j; over=check(); } if(over)break; } if(over)break; } //if(over)break; //} if(flag){ if(sum==n*m){ printf("0\n");//都是0,不需要变 }else{ printf("%d\n",times); for(int i=0;i<times;i++){ printf("%d %d\n",how[i].x,how[i].y); } } }else{//不存在这种情况 printf("-1\n"); } return 0; }