题目链接:https://ac.nowcoder.com/acm/contest/6871
#include
#define LL long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define PII pair
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9+7;
int main(){
int t;sc(t);
while(t--){
LL n,k;
scl2(n,k);
if(n%k){
cout<<"-1 -1 -1\n";
continue;
}n/=k;
int f=0;
for(LL i=2;i<=100;i++){
for(LL j=2;j<=100;j++){
LL kk=n-i-j;
if(kk>1&&__gcd(i,j)==1&&__gcd(i,kk)==1&&__gcd(j,kk)==1){
cout<
#include
#define LL long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define PII pair
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
map mp;//存原子式量
LL cal(string a)
{
LL ans = 0;
for (int i = 0; i < a.size(); i++)
{
if (i + 1 < a.size() && isdigit(a[i + 1]))//判断后面是不是数字
{
int p = i + 1;
LL s = 0;//数字可能很大,开long long
while (p < a.size() && isdigit(a[p]))
{
s = s * 10 + a[p] - '0';//拿s存数字
p++;
}
ans += mp[a[i]] * s;
i = p - 1;//到下一个字符前一个位置,因为后面要++
}
else
ans += mp[a[i]];
}
return ans;
}
int main()
{
mp['C'] = 13;
mp['H'] = 1;
mp['O'] = 17;
LL ans = 0;
string a;
cin >> a;
for (int i = 0; i < a.size(); i++)
{
if (a[i] == '(')
{
int p = i;
LL s = 0, tmp = 0;
while (a[p] != ')')
p++;
tmp = cal(a.substr(i + 1, p - i - 1));//括号内分子式量
p++;
if (isdigit(a[p]))//判断括号后面是不是数字
{
while (p < a.size() && isdigit(a[p]))
{
s = s * 10 + a[p] - '0';//存分子个数
p++;
}
}
else
s = 1;
ans += tmp * s;
i = p - 1;
}
else
{
//不是括号的话,处理方式一样的
if (i + 1 < a.size() && isdigit(a[i + 1]))
{
int p = i + 1;
LL s = 0;
while (p < a.size() && isdigit(a[p]))
{
s = s * 10 + a[p] - '0';
p++;
}
ans += mp[a[i]] * s;
i = p - 1;
}
else
ans += mp[a[i]];
}
// cout << "i:" << i << endl;
// cout << "ans:" << ans << endl;
}
cout << ans << endl;
system("pause");
return 0;
}
#include
#define LL long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define PII pair
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9+7;
int main(){
int t;cin>>t;
while(t--){
int n,cnt=0;cin>>n;
//cout<<"n:"<
#include
#define LL long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define PII pair
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9+7;
mapmp;
int main(){
int n,m,p;
sc3(n,m,p);
for(int i=0;i<(1<<(m-p));i++){//一共有(1<<(m-p))页,也就是2^(m-p)
LL x;scl(x);
mp[x]=i+1;//由于存在i=0,会对后面的判断产生影响,这边先给他算i+1,后面取出-1就好了
}
int q;sc(q);
while(q--){
char a[105];ss(a);
vectorb;
for(int i=0;is;
for(int j=0;j<4;j++){//自己会补零
s.push(tmp%2);
tmp/=2;
}
//由于上面存的是二进制余数,这边就要倒着存,所以用了栈
while(s.size()){
b.push_back(s.top());
s.pop();
}
}
//计算虚拟地址页号
LL tt=0,bas=1;
for(int i=32-p-1;i>=0;i--){
if(b[i])tt+=bas;
bas<<=1;
}
if(!mp[tt]){
cout<<"interrupt!"<=0;i--){//物理页号转二进制
int x=tmp%2;
b[i]=x;
tmp/=2;
}
for(int i=0;i<32;i+=4){//二进制转十六进制并输出
tmp=0;
for(int j=i;j
#include
#define LL long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define PII pair
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
LL a[maxn], dp[maxn], sum[maxn], p = 1e16;
int main()
{
int n, x;
sc2(n, x);
for (int i = 1; i <= n; i++)
{
scl(a[i]);
}
a[x] += p;
sum[1] = a[1];
for (int i = 3; i <= n; i += 2)
{
sum[i] = sum[i - 2] + a[i];//前奇数位的前缀和
}
for (int i = 2; i <= n; i++)
{
if (i & 1) //奇数位置的时候,dp[i-1]表示当前位不选,dp[i-2]+a[i]表示当前位选,但是由于相邻位不选,那么加上dp[i-2]的状态
dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
else //偶数的位置,由于要保证选满n/2个数,所以sum[i-1]表示当前为不选,前奇数位累加,个数一定等于n/2。dp[i-2]+a[i]表示当前位选,由于相邻位不选,加上dp[i-2]的状态
dp[i] = max(sum[i - 1], dp[i - 2] + a[i]);
}
cout << dp[n] - p << endl;
system("pause");
return 0;
}