Codeforces Round #747 (Div. 2)

哎!卡题了又!!!

A题

  • 题意
    在这里插入图片描述
  • 思路

可以从负数开始呀,- ( n − 1 ) (n-1) (n1) ~ n n n

  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
void solve()
{
	ll n;cin>>n;
    cout<<(-n+1)<<" "<<n<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

B题

  • 题意
    在这里插入图片描述
  • 思路

一眼猜出来肯定是 k k k 的二进制对应 1 1 1 的位置加上 2 i 2^i 2i

  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back

ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return res;
}
void solve()
{
	ll n,k;
    cin>>n>>k;
    ll ans = 0;
    for(int i=32;i>=0;i--){
        if((k>>i)&1){
            ans = (ans + power(n,i))%mod;
        }
    }
    ans %= mod;
    cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}

C题

  • 题意
    在这里插入图片描述
  • 思路

卡了好久,幸亏心态还可以;其实只要分情况讨论一下就可以了。
如果 s [ n − 1 ] = = c s[n-1]==c s[n1]==c,那么就可以直接输出 n n n,否则在 n / 2 + 1 n/2+1 n/2+1 - n n n 找一个 s [ i ] = = c s[i]==c s[i]==c的输出;在否则至少得需要两个了,因为 i i i n n n 消掉, n n n i i i 消掉,不会再出现一个数字可以同时把所有的消掉,因为他的二倍没有消掉,哎,还是一个思维套路吧,没有想到一开始。

  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back

const int maxn=1e6+10;//���������һ����Χ��
int prime[maxn];
int visit[maxn];//1����������0������
void Prime()
{
    visit[1]=1;
    for (int i = 2;i < maxn; i++) 
    {
        if (!visit[i]) 
        {
            prime[++prime[0]] = i;     
        }
        for (int j = 1; j <=prime[0] && i*prime[j] < maxn; j++) 
        {
            visit[i*prime[j]] = 1;
            if (i % prime[j] == 0) 
            {
                break;
            }
        }
    }
}

void solve()
{
	int n;char c;cin>>n>>c;
    string s;cin>>s;
    vector<int> vec;
    for(int i=0;i<n;i++){
        if(s[i] != c) vec.push_back(i+1);
    }
    if(!vec.size()){
        cout<<0<<endl;return;
    }
    if(s[n-1] == c){
        cout<<1<<endl;
        cout<<n<<endl;return;
    }
    for(int i=n/2+1;i<=n;i++){
        if(s[i-1]==c){
            cout<<1<<endl;cout<<i<<endl;return;
        }
    }
    cout<<2<<endl;cout<<n-1<<" "<<n<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("a.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    Prime();
	int t;
	cin >> t;
	while (t--)
		solve();
}

E1

  • 题意
    就是猜,一个完全二叉树,相邻节点不能涂规定的颜色
  • 思路

答案就是 a n s = 6 ( 根 节 点 ) ∗ 4 2 k − 2 ans=6(根节点)*4^{2^k-2} ans=6()42k2。记住 2 k 2^k 2k 不能取模。哎,因为这个贡献了好几发罚时。

  • 代码
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){

    cout<<s<<": "<<x<<endl;
}

#define PII pair<int,int>
#define x first
#define y second
#define PB push_back

ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1) res=(res*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return res%mod;
}
void solve()
{
	ll n,k;
    cin>>n>>k;
    ll ans = 0;
    for(int i=32;i>=0;i--){
        if((k>>i)&1){
            ans = (ans + power(n,i))%mod;
        }
    }
    ans %= mod;
    cout<<ans<<endl;
}
int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("a.txt", "r", stdin);
// 	freopen("aout.txt", "w", stdout);
// #endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll k;cin>>k;
    ll ans = 1;
    for(int i=1;i<=k;i++) ans *=2;
    ans-=2;
    //千万不要写成 power(2,k)-2;因为这个不能取模。
    // cout<<ans<<endl;
    ll aans = (power(4,ans) % mod)*6%mod;
    cout<<aans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯狂的码泰君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值