Educational Codeforces Round 88 (Rated for Div. 2)(A/B思维 C数学 D单调栈+ST表 E(数论,关于mod于因数的关系)F(咕咕咕))

A - Berland Poker

#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
ll n,m,k,t;


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	clock_t c1 = clock();
	//===========================================================
	read(t);
    while(t--){
        read(n),read(m),read(k);
        ll p=n/k;
        ll j=min(p,m);
        ll j2=(m-j)/(k-1);
        if((m-j)%(k-1)) j2++;
        write(j-j2);
        cerr<<j<<" "<<j2<<endl;
        putchar('\n');
    }
	//===========================================================
	std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}

B - New Theatre Square

#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
char mp[105][1005];
int x,y;
int t,n,m;


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	clock_t c1 = clock();
	//===========================================================
	read(t);
    while(t--){
        read(n),read(m),read(x),read(y);
        rep(i,1,n){
            rep(j,1,m){
                cin>>mp[i][j];
            }
        }
        if(2*x<=y){
            int cnt=0;
            rep(i,1,n){
                rep(j,1,m){
                    if(mp[i][j]=='.'){
                        cnt++;
                    }
                }
            }
            write(cnt*x);
        }
        else{
            int cnt1=0,cnt2=0;
            rep(i,1,n){
                rep(j,1,m){
                    if(mp[i][j]=='.'){
                        if(j+1<=m&&mp[i][j+1]=='.'){
                            cnt2++;
                            mp[i][j]=mp[i][j+1]='*';
                        }
                            else{
                            cnt1++;
                            mp[i][j]='*';
                        }
                    }
                }
            }
            write(cnt1*x+cnt2*y);
        }
        putchar('\n');
    }
	//===========================================================
	std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}

C - Mixing Water

首先,分情况:
若加入偶数杯,通过列式可知,温度和加入的杯数无关,所以,我们把偶数的情况单独拎出来比较。
对于奇数杯,我们可以写出通式: t n o w = ( ( c + h ) ∗ x − c ) / ( 2 ∗ x − 1 ) t_{now}=((c+h)*x-c)/(2*x-1) tnow=((c+h)xc)/(2x1),我们求导之后,发现这个函数是单调减的,所以,这里我们可以选择二分。但是,我们也可以再推一下。假设 t n o w = ( ( c + h ) ∗ x − c ) / ( 2 ∗ x − 1 ) = = t t_{now}=((c+h)*x-c)/(2*x-1)==t tnow=((c+h)xc)/(2x1)==t,我们可以算出: x = ( c − t ) / ( c + h − 2 ∗ t ) x=(c-t)/(c+h-2*t) x=(ct)/(c+h2t),此时,加入杯数为 a n s = ( c − h ) / ( c + h − 2 ∗ t ) ans=(c-h)/(c+h-2*t) ans=(ch)/(c+h2t),但是,因为这不是精确值,所以,我们需要左右枚举一番。

#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
int T;
ll c,h,t;
double cal(ll x){
    int t1=x/2,t2=x-t1;
    return (1.0*t2*h+1.0*t1*c)/x;
}
#define eps 1e-9

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	clock_t c1 = clock();
	//===========================================================
	read(T);
    while(T--){
        read(h),read(c),read(t);
        if(h==t) write(1);
        else{
            int ans=(double)((1.0*c-h)/(1.0*c+h-2*t));
            double xx=fabs(cal(ans)-t);
            if(ans<=0){
                write(2);
                putchar('\n');
                continue;
            }
            int l=ans-5,r=ans+5;
            rep(i,l,r){
                if(i<=0) continue;
                if(fabs(cal(i)-t)<xx){
                    ans=i;
                    xx=fabs(cal(i)-t);
                }
            }
            if(fabs(cal(2)-t)<fabs(cal(ans)-t)) ans=2;
            write(ans);
        }
        putchar('\n');
    }
	//===========================================================
	std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}

D-Yet Another Yet Another Task

好像正解是dp。。但是,看到有大佬写了个st表+单调栈的方法,感觉更好理解。因为它只抽掉中间的一个数,所以,我们可以枚举这个数。很容易可以想到,我们抽调的这个数,是为了让结果尽量小,那么,就应该是这个区间内最大的数,所以,我们可以利用单调栈求出这个数左右两侧的沿着这个数到两端方向的最大单调递减区间,并记录下区间的边界,就可以得到每个数对应的区间。
之后,我们再用st表,去维护一个前缀和。
在查询的时候,我们就查询st表中,在右侧递减区间内的最大前缀和和左侧递减区间中的最小前缀和,两个值的差就是删除这个数的对应区间内能得到的最大子段和,减掉要删去的数,就是所得值。我们只要枚举中间值就行了。

#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register ll i = a; i <= n; ++ i)
#define per(i, a, n) for(register ll i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
#define re register
const int maxn=1e5+10;
ll a[maxn];
ll s[maxn];
ll st_min[maxn][20];
ll st_max[maxn][20];
ll l[maxn],r[maxn];
ll lg[maxn];
ll n;
void build(){//st表维护前缀和,记录在每个区间内的最大/最小前缀和
    rep(i,1,n){
        lg[i]=lg[i/2]+1;
    }
    rep(i,1,n) st_min[i][0]=s[i],st_max[i][0]=s[i];
    for(re int j=1;j<=25;j++){
        for(re ll i=0;i+(1<<j)-1<=n;i++){
            st_max[i][j]=max(st_max[i][j-1],st_max[i+(1<<(j-1))][j-1]);
            st_min[i][j]=min(st_min[i][j-1],st_min[i+(1<<(j-1))][j-1]);
        }
    }
}
//查询操作
ll query_max(ll l,ll r){
    ll k =lg[r-l+1]-1;
    return max(st_max[l][k],st_max[r-(1<<k)+1][k]);
}

ll query_min(ll l,ll r){
    ll k=lg[r-l+1]-1;
    return min(st_min[l][k],st_min[r-(1<<k)+1][k]);
}

void get_edge(){
    ll st[maxn]={0};//手写栈
    ll top=0;
    rep(i,1,n){
        while(top&&a[st[top]]<=a[i]){//目前栈顶对应的值比他小,说明还能拓展,继续pop
            top--;
        }
        l[i]=st[top];
        st[++top]=i;
    }
    top=0;
    st[0]=n+1;
    per(i,1,n){
        while(top&&a[i]>=a[st[top]]){//同上
            top--;
        }
        r[i]=st[top];
        st[++top]=i;
    }
    rep(i,1,n) l[i]++,r[i]--;
    //因为上面边界分别是从0和n+1开始的,而且每次记录的是比他小一或大一单位的数,所以,需要缩小一下范围。
}


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	clock_t c1 = clock();
	//===========================================================
	read(n);
    rep(i,1,n) read(a[i]);
    rep(i,1,n) s[i]=s[i-1]+a[i];//求前缀和
    build();
    get_edge();
    ll ans=-inf;
    rep(i,1,n){//暴力查询
        ll tmp=query_max(i,r[i])-query_min(l[i]-1,i-1);
        ans=max(ans,tmp-a[i]);
    }
    write(ans);
	//===========================================================
	std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}

E - Modular Stability

想不明白什么时候才满足题目给的式子,大佬给了我答案:当每个除数中间存在倍数关系的时候。
证明:还是交给大佬吧。。

#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register ll i = a; i <= n; ++ i)
#define per(i, a, n) for(register ll i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const ll mod=998244353;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}

//==============================================================
const int maxn=5e5+10;
ll fac[maxn];
ll inv[maxn];
ll n,k;
void init(){
    fac[0]=1;
    rep(i,1,maxn+1){
        fac[i]=(fac[i-1]*i)%mod;
    }
    inv[(int)(5e5)]=ksm((int)(fac[(int)5e5]),mod-2)%mod;
    for(int i=5e5-1;i>=0;--i){
        inv[i]=inv[i+1]*(i+1)%mod;
    }
}

ll C(ll n,ll m){
    if(n<m) return 0;
    return ((fac[n]*inv[n-m])%mod*inv[m])%mod;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	clock_t c1 = clock();
	//===========================================================
    init();
    read(n),read(k);
    ll ans=0;
    rep(i,1,n){
        ans=(ans+C(n/i-1,k-1)%mod)%mod;
    }
    write(ans);
	//===========================================================
	std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值