CF Contest-1066

A  Vova and Train

#include <bits/stdc++.h>
#include <iostream>
#define X 10005
#define inf 0x3f3f3f3f
#define PI 3.141592653589793238462643383
#define IO  ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+10;
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
    {
		ll L, v, l, r;
		cin>>L>>v>>l>>r;
		ll ans = (l - 1) / v + L / v - r / v;
		printf("%lld\n", ans);
	}
}

B    Heaters

给出每个位置是否有热水器,然后给出热水器的作用距离(每个作用距离都一样)现在每个热水器都处于关闭状态,问最少要开几个热水器使得所有的位置都可以被覆盖

#include <bits/stdc++.h>
#include <iostream>
#define X 10005
#define inf 0x3f3f3f3f
#define PI 3.141592653589793238462643383
#define IO  ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+10;
int a[maxn];
int n,r,cnt=0,l= 0,i=1,pos,ans;
int tag=0;
int main()
{
	cin>>n>>r;
	for (int i = 1; i <= n;i++) cin>>a[i];
	for(int i=1;i<=n;)
	{
		pos=i+r-1,ans=0;
		while (pos>l)
		{
			if (a[pos])
            {
				ans=pos;
				break;
			}
			else --pos;
		}
		if (ans==0)
		{
			cout<<-1<<endl;
			tag=1;
			break;
		}
		else
		{
			l=ans;
			i=ans+r;
			cnt++;
		}
	}
	if(!tag)
	cout<<cnt<<endl;
	return 0;
}

C  Books Queries

给q次操作,可以往书架最右面或者往书架最左面放书或者查询一本书离边缘的最短距离
用两个数组记录一本书是第几本放在左面或者右面的书,这样就可以保证如果这本书当时是通过放在左面进入书架,
则距离是min(L+b[id]-1,R-b[id]) 如果是通过右面则是min(R+a[id]-1,L-a[id])
谢大佬@@

#include <bits/stdc++.h>
#include <iostream>
#define X 10005
#define inf 0x3f3f3f3f
#define PI 3.141592653589793238462643383
#define IO  ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e6+10;
int main()
{
    int n,id;
    char str;
    while(cin>>n)
    {
        int _l=1,_r=0,l=0,r=1;
        for(int i=0;i<n;++i)
        {
            cin>>str>>id;
            if(str=='L') a[id]=++l,b[id]=--_l;//a[id]左面所在的位置 b[id]第几本从左面放的书
            if(str=='R') a[id]=--r,b[id]=++_r;//a[id]右面的位置 b[id]第几本从右面放的书
            if(str=='?') cout<<min(l-a[id],_r-b[id])<<endl;
        }
    }
}

E   Binary Numbers AND Sum

题意:给出两个01串ab 当b最后一位为1的时候就a&b的结果进行计入,为0不做处理,然后b右移一位,最后统计累加计入的和

统计b中1的个数 从a的低位开始,当为1时,快速幂进行计算  累加?

#include <bits/stdc++.h>
#include <iostream>
#define X 10005
#define inf 0x3f3f3f3f
#define PI 3.141592653589793238462643383
#define IO  ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e6+10;
char a[maxn],b[maxn];
ll Pow(ll x,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*x%mod;
        n>>=1;
        x=x*x%mod;
    }
    return ans;
}
int main()
{
    int n,m,cnt=0;
    cin>>n>>m;
    for(int i=n-1;i>=0;--i)cin>>a[i];
    for(int i=m-1;i>=0;--i){cin>>b[i];if(b[i]=='1')cnt++;}
    ll ans=0;
    for(int i=0,j=0;i<n&&cnt;++i,++j)
    {
        if(a[i]=='1')
            ans=(ans+Pow(2,i)*ll(cnt)%mod)%mod;
        if(b[i]=='1')cnt--;
    }
    cout<<ans<<endl;
    return 0;
}

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值