本文主要是介绍codeforces 15 CDE,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100],b[100];
const int t = 0x7fffffff;
ll rem1, rem2, xor1, xor2, ans, xi, mi;
int main(){
int testn;
ans = 0;
cin>>testn;
for (int i=0; i<testn; i++){cin>>xi>>mi;rem1 = (xi-1) % 4;rem2 = (xi+mi-1) %4;switch(rem1){case 0 : xor1 = xi - 1;break;case 1 : xor1 = 1;break;case 2 : xor1 = xi;break;case 3 : xor1 = 0;break;}switch(rem2){case 0 : xor2 = xi+mi-1;break;case 1 : xor2 = 1;break;case 2 : xor2 = xi+mi;break;case 3 : xor2 = 0;break;}if (xi == 1) ans ^= xor2;else ans ^= xor1 ^ xor2;
}if (ans == 0){cout<<"bolik"<<endl;}else cout<<"tolik"<<endl;}
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (ll i=a; i<n; i++)
#define pb push_back
#define pii pair<ll, ll>
#define fi first
#define se second
#define maxn 1005
#define maxint 0x7fffffff
#define ll long long
int que[maxn];
ll n, m, a, id, b, zuidigaodu, S, E;
int Q[maxn*maxn];
ll min_c;
int used[maxn*maxn];
int mp[maxn][maxn];
ll sum[maxn*2][maxn*2];
int minr[maxn][maxn];
ll get_id (ll x, ll y){return (x*(m-b+1) + y) ;
}
struct square {int x, y,original_id;ll cost;const bool operator < (const square &cp){return (cost < cp.cost|| ((cost == cp.cost) && (x<cp.x))|| ((cost == cp.cost) && (x==cp.x) && (y<cp.y)));}
}sqr[maxn*maxn];int main(){cin>>n>>m>>a>>b;rep(i, 0, n){rep(j, 0, m){scanf("%d", &mp[i][j]);}}
///倒着不用处理边界for (int i=n-1; i>=0; i--){ for (int j=m-1; j>=0; j--){sum[i][j] = mp[i][j] + sum[i+1][j] + sum[i][j+1] - sum[i+1][j+1];}}
///正着才能处理左上角 不至于改变后面的状态
/**/rep(i, 0, n-a+1){rep(j, 0, m-b+1){sum[i][j] = sum[i][j] - sum[i+a][j] - sum[i][j+b] + sum[i+a][j+b];}}
/* rep(i, 0, n){rep(j, 0, m){cout<<sum[i][j]<<" ";}cout<<endl;}
*/
///倒着处理方便表示以j为左端点右边的a个点的minrep(i, 0, n){S = E = 0;/*下标可有多种写法 但是必须使S指向第一个元素while (S<=E && mp[i][que[E]]>mp[i][j]) 这种就是错的 必须满足两个条件才能到-1 导致初始化失败否则S永远指向0 且 que[S] = 0*/for (int j=m-1; j>=0; j--){ while (S<E && mp[i][que[E-1]]>mp[i][j])E--;que[E++] = j; while (S<E && que[S]>=j+b)S++;minr[i][j] = mp[i][que[S]];}}
///一样倒着 用mp储存二位结果节省空间 因为mp没用了rep(j, 0, m){S = E = 0;for (int i=n-1; i>=0; i--){while (S<E && minr[que[E-1]][j]>minr[i][j])E--;que[E++] = i;while (S<E && que[S]>=i+a)S++;mp[i][j] = minr[que[S]][j];}}memset(used, 0, sizeof (used));rep(i, 0, n-a+1){rep(j, 0, m-b+1){id = get_id(i, j);sqr[id].original_id = id;sqr[id].x = i; sqr[id].y = j; sqr[id].cost = sum[i][j] - (ll) a*b*mp[i][j];//herelong long保护//cout<<"id = "<<id<<endl;}}
/*rep(i, 0, (n-a+1) * (m-b+1)){cout<<"original_id = "<<sqr[i].original_id<<endl;cout<<"cost = "<<sqr[i].cost<<endl;cout<<"x = "<<sqr[i].x<<" y = "<< sqr[i].y <<endl;puts("");}puts("after\n");rep(i, 0, (n-a+1) * (m-b+1)){cout<<"original_id = "<<sqr[i].original_id<<endl;cout<<"cost = "<<sqr[i].cost<<endl;cout<<"x = "<<sqr[i].x<<" y = "<< sqr[i].y <<endl;puts("");}
*/ sort(sqr, sqr+(n-a+1)*(m-b+1));ll cnt = 0;rep(i, 0, (n-a+1)*(m-b+1)){if (!used[sqr[i].original_id]){Q[cnt++] = i;rep(k, sqr[i].x-a+1, sqr[i].x+a){rep(l, sqr[i].y-b+1, sqr[i].y+b){if (k<0 || k>=(n-a+1) || l<0 || (l>=m-b+1)) continue;used[get_id(k, l)] = 1;}}}}printf("%lld\n", cnt);rep(j, 0, cnt){ll i = Q[j];printf("%d %d %lld\n", sqr[i].x+1, sqr[i].y+1, sqr[i].cost);}//输出要加1
}
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000009
using namespace std;ll a=2,b=2,c=4,n;int main(int argc, char const *argv[])
{scanf("%I64d",&n);a=2,b=2,c=4;while(n-=2){ printf("n = %lld\n", n);a=a*2%mod,c=c*(a-3)%mod,b=(b+c)%mod;printf("a = %lld c = %lld b = %lld\n", a, c, b);}printf("%I64d\n",(b*b+1)*2%mod);printf("%I64d\n",(b*b+1)*2- c*c*2 - c*2);return 0;
}
每层从上一层走到巷子口都是4种 然后过巷子就是2^i-3 然后再乘上上面的走法
a是算单个巷子的指数
b是把每层结果加起来
c是这层以上所有巷子的乘法法则
或者这样说 每次都是沿着最左边走 只在2n层分叉
篮圈到绿圈4种 绿圈算作巷子入口 绿圈走到红圈13种 乘起来4*13
再乘上上面所有巷子
这篇关于codeforces 15 CDE的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!