Codeforces Round #514 (Div. 2)

 A

 

Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized nn regular customers, the i-th of which comes after ti minutes after the beginning of the day, and his service consumes li minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.

Vasya is a bit lazy, so he likes taking smoke breaks for a minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

题目大意

Vasya工作总时长L分钟,他优先服务顾客(在ti分钟到来,并消耗li分钟),Vasya在空闲时休息(消耗a分钟),休息可以连续。

 

问:Vasya可以休息多少次

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
ll t[N],l[N];
int main(){
    ll n, L,a;
    while (~scanf("%lld%lld%lld", &n, &L,&a) )
	{
        ll ans=0;
        for(int i=1;i<=n;i++)
        	scanf("%lld%lld",&t[i],&l[i]);
        ans+=t[1]/a;    //  t[1]>=0
	    for(int i=2;i<=n;i++)
        {
            ll TT=t[i]-t[i-1]-l[i-1];
            ans+=TT/a;
        }
        ans+=(L-t[n]-l[n])/a;
        printf("%lld\n",ans);
	}
    return 0;
}

 

 

B

 

Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an n×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×3 square without its central cell if it is completely contained inside the grid, as shown below.

xxx
x. x
xxx


Determine whether is it possible to forge the signature on an empty n×m n×m grid.

题目大意:Andrey的笔能画出3*3的方阵(如上),给一个目标签名方阵A,问这支笔能不能完成目标方阵。

题目比较晦涩,但思路是简单的,通过模拟,在目标方阵A寻找符合 笔的小方阵,复制到方阵B,最后比较A与B是否一样,一样则代表笔能写出A方阵。

 

 

转载
#include<bits/stdc++.h>
using namespace std;
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.71828182845904
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long

char a[1111][1111],b[1111][1111];
int main()
{
    memset(a,'.');
    memset(b,'.');
    int n,m;
    cin>>n>>m;
    int l,r;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            cin>>a[i][j];
        }
    for(int i=0; i<n-2; i++)
        for(int j=0; j<m-2; j++)
        {
            if(a[i][j]=='#'&&a[i][j+1]=='#'&&a[i][j+2]=='#'&&a[i+1][j]=='#'&&a[i+2][j]=='#'&&a[i+1][j+2]=='#'&&a[i+2][j+1]=='#'&&a[i+2][j+2]=='#')
                b[i][j]='#',b[i][j+1]='#',b[i][j+2]='#',b[i+1][j]='#',b[i+2][j]='#',b[i+1][j+2]='#',b[i+2][j+1]='#',b[i+2][j+2]='#';
        }
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            if(a[i][j]!=b[i][j])
            {
                //cout<<i<<j<<endl;
                cout<<"NO"<<endl;
                return 0;
            }
    cout<<"YES"<<endl;
    return 0;
}

 

 

C

 

Let's call the following process a transformation of a sequence of length nn.

If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of n integers: the greatest common divisors of all the elements in the sequence before each deletion.

You are given an integer sequence 1,2,…,n Find the lexicographically maximum result of its transformation.

A sequence a1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bn, if there is an index i such that aj=bj for all j<i and ai>bi.

题目大意

给定一个n,代表1,2,~N  n个数,操作1(取出GCD,放入结果串中),操作2(删去任意一个数)

求给定顺序最大的结果串 

给定顺序a>b 则从一个相等值后,ai>bi.

由于题目所给串取出第一个GCD必是1,为了让GCD早点变大,删一半左右数GCD变成2最优(大部分情况),

所以优先删去奇数,再保留4的倍数,8的倍数……

结果串大致为1……1(任意个)2……2(任意个)4……     X(最后一位数可能为3的倍数,数值为规律数/2*3)

例:

n=5
  1 2 3 4 5    5个数
  2 4          2个数
    4            1个数
n=16
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                16个数
  2 4 6 8 10 12 14 16                                   8个数
  4 8 12 16                                             4个数
  8 16                                                  2个数
  16                                                    1个数

但这适用于大部分情况

题目中给到了一个特殊例子,n=3.

所以必须给最后一一个数加一个特判(剩两个数时,留下较大的数,使GCD更大)。

#include<bits/stdc++.h>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.71828182845904
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define write(x) printf("%d ",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;


char a[1005][1005],b[1005][1005];
int main()
{
    int n;
    read(n);
    int x=n;
    if (n>1)
        {
        int xx=n-n/2;
            static int ans=1;
        while(n>1)
            {
            for (int i=1;i<=xx;i++)write(ans);
            ans*=2;
            n=n-xx;
            xx=n-n/2;
           // if (n==2)break;
           }
           if (ans/2*3<=x)write (ans/2*3);
           else write (ans);
        }
    return 0;
}

转载一份更巧妙的代码

转载
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int n;
void solve(int k,int p){
	if(k==1){
		printf("%d ",p);
		return;
	}
	if(k==2){
		printf("%d %d ",p,2*p);
		return;
	}
	if(k==3){
		printf("%d %d %d ",p,p,3*p);
		return;
	}
	for(int i=1;i<=(k+1)/2;i++)printf("%d ",p);
	solve(k-(k+1)/2,p*2);
}
int main(){
	scanf("%d",&n);
	solve(n,1);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值