Codeforces Round #322 (Div. 2)

传送门:A. Vasya the Hipster  (极水题)

#include <bits/stdc++.h>
#define pr(x) cout << #x << "= " << x << "  "
#define pl(x) cout << #x << "= " << x << endl;
#define Memset(x, a) memset(x, a, sizeof(x))
#define ll __int64
using  namespace  std;
const int inf=0x3f3f3f3f;
int  a,b;

int  main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    cin>>a>>b;
    if(a>b)swap(a,b);
    cout<<a<<" "<<(b-a)/2<<endl;
    return 0;
}

传送门: B. Luxurious Houses   (水题)

题意:~

思路:也是水题一枚,从后往前扫一遍就不会TLE了

#include <bits/stdc++.h>
#define pr(x) cout << #x << "= " << x << "  "
#define pl(x) cout << #x << "= " << x << endl;
#define Memset(x, a) memset(x, a, sizeof(x))
#define ll __int64
using  namespace  std;
const int inf=0x3f3f3f3f;
int n,a[100005],ans[100005];

int  main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int b=0;
    ans[n-1]=0;
    for(int i=n-1; i>=1; i--){
        b=max(b,a[i]);
        if(b<a[i-1])ans[i-1]=0;
        else  ans[i-1]=b-a[i-1]+1;
    }
    for(int i=0; i<n; i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}

传送门: C. Developing Skills  (贪心)

思路:这是一道简单的贪心,我们将每一个数字按照最后一位的大小排一个序,然后优先加给最后一位大的,如果有多的那么就分给每一个,然是不能超过100(刚开始没注意这个WA在test5了)

#include <bits/stdc++.h>
#define pr(x) cout << #x << "= " << x << "  "
#define pl(x) cout << #x << "= " << x << endl;
#define Memset(x, a) memset(x, a, sizeof(x))
#define ll __int64
using  namespace  std;
const int inf=0x3f3f3f3f;
int n,k,a[100005],b[100005];


inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int  main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    n=read();k=read();
    int  ans=0,cnt=0;
    for(int i=1; i<=n; i++){
        a[i]=read();
        ans+=a[i]/10;
        if(a[i]==100)continue;//先把等于100情况除去
        b[++cnt]=10-a[i]%10;
        a[i]+=b[cnt];
    }
    sort(b+1,b+cnt+1);
    bool flag=true;
    for(int i=1; i<=cnt; i++){
        if(k>=b[i]){  ans++; k-=b[i];}
        else{
            flag=false;
            break;
        }
    }
    if(flag){  //如果k有的多
        int sum=0;
        for(int i=1; i<=n; i++){
            sum+=(100-a[i])/10;
        }
        ans+=min(sum,k/10);  //再多也不能超100
    }
    cout<<ans<<endl;
    return 0;
}
传送门: D. Three Logos   (暴力)

题意:

给你三个矩形,问你是否能拼成一个正方形

思路:这题数据小,无脑暴力也行,但是CF的题经常是可以通过多思考来优化的

这个题首先明确能构成正方形的充要条件就是:最长边^2=三个矩形的面积和,同时这个最长边即作为正方形的边长len。具体地,首先得到三个矩形的长宽,先旋转为卧倒的矩形(上下边>=左右腰)。之后找到最长边,判断能否构成正方形。如果能,那么这个最长边的矩形一定可以卧放在正方形的顶部(也可以放在其他地方,但一定可以旋转到顶部)。
然后剩下下面的部分,这个地方有一些陷阱,最简单规避陷阱的方法就是分情况讨论,要不然就是三个矩形都依次卧放;要不就是两个矩形都竖着放。那么就试着枚举一下,随便选一个剩下的矩形(这里称之为X),如果X的较长边==len或者X的较短边刚好加上顶上矩形的腰长==len,那么就不用旋转;否则就旋转。最后的一个矩形把剩下的地方补齐即可。
#include <bits/stdc++.h>
#define pr(x) cout << #x << "= " << x << "  "
#define pl(x) cout << #x << "= " << x << endl;
#define Memset(x, a) memset(x, a, sizeof(x))
#define ll __int64
using  namespace  std;
const int inf=0x3f3f3f3f;

struct Rec
{
	int l, w;
	char ch;
	bool operator <( const Rec& rhs )const{
		return l < rhs.l;
	}
	int sq(){
		return l*w;
	}
}rec[4];

int  main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    while(scanf( "%d%d%d%d%d%d", &rec[1].l, &rec[1].w, &rec[2].l, &rec[2].w, &rec[3].l, &rec[3].w ) == 6)
	{
		for(int i = 1; i <= 3; i++){
			if(rec[i].l < rec[i].w)swap( rec[i].l, rec[i].w );
			rec[i].ch = 'A' - 1 + i;
		}
        sort( rec + 1, rec + 4 );

		int len = rec[3].l;

		if((rec[3].l*rec[3].l) != (rec[1].sq() + rec[2].sq() + rec[3].sq()))
		{
			printf( "-1\n" );
			continue;
		}
        printf( "%d\n", len );

		for(int i = 1; i <= rec[3].w; i++){
			for(int j = 1; j <= rec[3].l; j++){
				printf( "%c", rec[3].ch );
			}
			printf( "\n" );
		}

		if(rec[2].l!=len&&rec[3].w + rec[2].w != len) swap( rec[2].l, rec[2].w );
		for(int i = 1; i <= rec[2].w; i++){
			for(int j = 1; j <= rec[2].l; j++){
				printf( "%c", rec[2].ch );
			}for(int j = 1; j <= len - rec[2].l; j++){
				printf( "%c", rec[1].ch );
			}
			printf( "\n" );
		}

		for(int i = 1; i <=len-rec[3].w- rec[2].w; i++){
			for(int j = 1; j <= len; j++){
				printf( "%c", rec[1].ch );
			}
			printf( "\n" );
		}
    }
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值