哎!卡题了又!!!
A题
- 题意
- 思路
可以从负数开始呀,- ( n − 1 ) (n-1) (n−1) ~ 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[n−1]==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(根节点)∗42k−2。记住 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;
}