codeforces 15 CDE

2024-06-11 05:18
文章标签 15 codeforces cde

本文主要是介绍codeforces 15 CDE,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

C. Industrial Nim
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

There are n stone quarries in Petrograd.

Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.

Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses.

Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik».

Input

The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.

Output

Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.

Examples
input
Copy
2
2 1
3 2
output
tolik
input
Copy
4
1 1
1 1
1 1
1 1
output
bolik
#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;}
D. Map
time limit per test
2 seconds
memory limit per test
128 megabytes
input
standard input
output
standard output

There is an area map that is a rectangular matrix n × m, each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occupy a rectangle a × b cells on the map. To start construction works in a particular place Peter needs to remove excess ground from the construction site where a new city will be built. To do so he chooses a cell of the minimum height within this site, and removes excess ground from other cells of the site down to this minimum level. Let's consider that to lower the ground level from h2 to h1 (h1 ≤ h2) they need to remove h2 - h1 ground units.

Let's call a site's position optimal, if the amount of the ground removed from this site is minimal compared to other possible positions. Peter constructs cities according to the following algorithm: from all the optimum site's positions he chooses the uppermost one. If this position is not unique, he chooses the leftmost one. Then he builds a city on this site. Peter repeats this process untill he can build at least one more city. For sure, he cannot carry out construction works on the occupied cells. Would you, please, help Peter place cities according to the algorithm?

Input

The first line contains four space-separated integers: map sizes nm and city sizes ab (1 ≤ a ≤ n ≤ 10001 ≤ b ≤ m ≤ 1000). Then there follow n lines, each contains m non-negative space-separated numbers, describing the height matrix. Each number doesn't exceed 109.

Output

In the first line output k — the amount of constructed cities. In each of the following k lines output 3 space-separated numbers — the row number and the column number of the upper-left corner of a subsequent construction site, and the amount of the ground to remove from it. Output the sites in the order of their building up.

Examples
input
Copy
2 2 1 2
1 2
3 5
output
2
1 1 1
2 1 2
input
Copy
4 4 2 2
1 5 3 4
2 7 6 1
1 1 2 2
2 2 1 2
output
3
3 1 2
3 3 3
1 2 9

#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
}
E. Triangles
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels, where n is an even number.

In the local council you were given an area map, where the granny's house is marked by point H, parts of dense forest are marked grey (see the picture to understand better).

After a long time at home Peter decided to yield to his granny's persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics:

  • it starts and ends in the same place — the granny's house;
  • the route goes along the forest paths only (these are the segments marked black in the picture);
  • the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
  • the route cannot cross itself;
  • there shouldn't be any part of dense forest within the part marked out by this route;

You should find the amount of such suitable oriented routes modulo 1000000009.

The example of the area map for n = 12 is given in the picture. Since the map has a regular structure, you can construct it for other n by analogy using the example.

Input

The input data contain the only even integer n (2 ≤ n ≤ 106).

Output

Output the only number — the amount of Peter's routes modulo 1000000009.

Examples
input
Copy
2
output
10
input
Copy
4
output
74

#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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1050287

相关文章

Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单

《Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单》:本文主要介绍Springboot的ThreadPoolTaskScheduler线... 目录ThreadPoolTaskScheduler线程池实现15分钟不操作自动取消订单概要1,创建订单后

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

Adblock Plus官方规则Easylist China说明与反馈贴(2015.12.15)

-------------------------------特别说明--------------------------------------- 视频广告问题:因Adblock Plus的局限,存在以下现象,优酷、搜狐、17173黑屏并倒数;乐视、爱奇艺播放广告。因为这些视频网站的Flash播放器被植入了检测代码,而Adblock Plus无法修改播放器。 如需同时使用ads

15 组件的切换和对组件的data的使用

划重点 a 标签的使用事件修饰符组件的定义组件的切换:登录 / 注册 泡椒鱼头 :微辣 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-