Codeforces 984 扫雷check 欧几里得b进制分数有限小数判定 f函数最大连续子段
A
- /* Huyyt */
- #include <bits/stdc++.h>
- #define mem(a,b) memset(a,b,sizeof(a))
- #define mkp(a,b) make_pair(a,b)
- #define pb push_back
- using namespace std;
- typedef long long ll;
- const long long mod = 1e9 + ;
- const int N = 2e5 + ;
- int num[];
- int main()
- {
- int n;
- cin >> n;
- for(int i=;i<=n;i++)
- {
- cin >> num[i];
- }
- sort(num+,num++n);
- int now=;
- if(n%)
- {
- cout<<num[n/+]<<endl;
- }
- else
- {
- cout<<num[n/]<<endl;
- }
- }
B
- /* Huyyt */
- #include <bits/stdc++.h>
- #define mem(a,b) memset(a,b,sizeof(a))
- #define mkp(a,b) make_pair(a,b)
- #define pb push_back
- const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
- using namespace std;
- typedef long long ll;
- const long long mod = 1e9 + ;
- const int N = 2e5 + ;
- char f[][];
- int n, m;
- bool ok(int x, int y)
- {
- if (x > n || x < )
- {
- return false;
- }
- if (y > m || y < )
- {
- return false;
- }
- return true;
- }
- int main()
- {
- cin >> n >> m;
- for (int i = ; i <= n; i++)
- {
- scanf("%s", f[i] + );
- }
- for (int i = ; i <= n; i++)
- {
- for (int j = ; j <= m; j++)
- {
- if (f[i][j] == '*')
- {
- continue;
- }
- if (f[i][j] == '.')
- {
- for (int w = ; w < ; w++)
- {
- int dx = i + dir[w][];
- int dy = j + dir[w][];
- if (ok(dx, dy))
- {
- if (f[dx][dy] == '*')
- {
- cout << "NO" << endl;
- return ;
- }
- }
- }
- }
- else
- {
- int now = ;
- int cur = f[i][j] - '';
- for (int w = ; w < ; w++)
- {
- int dx = i + dir[w][];
- int dy = j + dir[w][];
- if (ok(dx, dy))
- {
- if (f[dx][dy] == '*')
- {
- now++;
- }
- }
- }
- if (now != cur)
- {
- cout << "NO" << endl;
- return ;
- }
- }
- }
- }
- cout << "YES" << endl;
- return ;
- }
C
好题。。应该是我做过最难的2C了
给你 p q b 三个1e18的数 问你在b进制下p/q能不能被有限地表现出来
首先把p与q约分 考虑1/q能不能在b进制在被表现出来
因为b进制下每退一位所表示的数就小b倍
所以我们可以把被除数乘上b再除q就是这一位小数的值 即\(\frac{3*4}{5}=2\)
同时被除数变为\(\frac{3}{5}\)\(\%\) \(\frac{1}{4}\)=\(\frac{(3*4)\%5}{5}\)=\(\frac{2}{5}\)
这样进行下去看能不能在某一步被除数分子乘上b是q的倍数
即存在n使得 \(b^{n}\ mod\ q=0\) 但是我们不可能枚举n来检验是否存在
由唯一分解定理可知 \(b^{n}\ mod\ q=0\) 等价于b的因子中存在所有q的质因子
- /*Huyyt*/
- #include<bits/stdc++.h>
- #define mem(a,b) memset(a,b,sizeof(a))
- #define pb push_back
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- const ll LLmaxn = 2e18;
- const int N = ;
- int n;
- inline ll readint()
- {
- char c = getchar();
- ll ans = ;
- while (c < '' || c > '')
- {
- c = getchar();
- }
- while (c >= '' && c <= '')
- {
- ans = ans * 10LL + c - '', c = getchar();
- }
- return ans;
- }
- ll gcd(ll a, ll b)
- {
- ll t;
- while (b)
- {
- t = b;
- b = a % b;
- a = t;
- }
- return a;
- }
- int main()
- {
- n=readint();
- ll p, q, b;
- for (int i = ; i <= n; i++)
- {
- p=readint(),q=readint(),b=readint();
- ll now = gcd(p, q);
- p /= now, q /= now;
- if (q == )
- {
- cout << "Finite" << endl;
- continue;
- }
- p %= q;
- if (p == )
- {
- cout << "Finite" << endl;
- continue;
- }
- now = gcd(q, b);
- while (now != )
- {
- while (q % now == )
- {
- q /= now;
- }
- now=gcd(q,b);
- }
- if (q == )
- {
- cout << "Finite" << endl;
- }
- else
- {
- cout << "Infinite" << endl;
- }
- }
- }
D
给你一个f函数(类似于石子合并花费 只是把+变成XOR操作)
直接n2用类似石子合并的思想先把小的区间处理出来dp[i][i + len] = dp[i][i + len - 1] ^ dp[i + 1][i + len]
再汇总dp[i][i + len] = max(max(dp[i][i + len - 1], dp[i + 1][i + len]), dp[i][i + len])
- /*Huyyt*/
- #include<bits/stdc++.h>
- #define mem(a,b) memset(a,b,sizeof(a))
- #define pb push_back
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- const ll LLmaxn = 2e18;
- const int N = ;
- inline int readint()
- {
- char c = getchar();
- int ans = ;
- while (c < '' || c > '')
- {
- c = getchar();
- }
- while (c >= '' && c <= '')
- {
- ans = ans * + c - '', c = getchar();
- }
- return ans;
- }
- int number[];
- int dp[][];
- int main()
- {
- int now = ;
- int n;
- n = readint();
- for (int i = ; i <= n; i++)
- {
- number[i] = readint();
- }
- for (int i = ; i <= n; i++)
- {
- dp[i][i] = number[i];
- }
- for (int len = ; len <= n - ; len++)
- {
- for (int i = ; i <= n - len; i++)
- {
- dp[i][i + len] = dp[i][i + len - ] ^ dp[i + ][i + len];
- }
- }
- for (int len = ; len <= n - ; len++)
- {
- for (int i = ; i <= n - len; i++)
- {
- dp[i][i + len] = max(max(dp[i][i + len - ], dp[i + ][i + len]), dp[i][i + len]);
- }
- }
- int l, r;
- int q;
- q = readint();
- while (q--)
- {
- l = readint(), r = readint();
- cout << dp[l][r] << endl;
- }
- }
Codeforces 984 扫雷check 欧几里得b进制分数有限小数判定 f函数最大连续子段的更多相关文章
- Vulnerable Kerbals CodeForces - 772C【拓展欧几里得建图+DAG上求最长路】
根据拓展欧几里得对于同余方程 $ax+by=c$ ,有解的条件是 $(a,b)|c$. 那么对于构造的序列的数,前一个数 $a$ 和后一个数 $b$ ,应该满足 $a*x=b(mod m)$ 即 $ ...
- Codeforces Round #538 (Div. 2) C 数论 + 求b进制后缀零
https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a ...
- Codeforces Round #444 (Div. 2)A. Div. 64【进制思维】
A. Div. 64 time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions
题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...
- Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)
补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...
- [codeforces 200 E Tractor College]枚举,扩展欧几里得,三分
题目出自 Codeforces Round #126 (Div. 2) 的E. 题意大致如下:给定a,b,c,s,求三个非负整数x,y,z,满足0<=x<=y<=z,ax+by+cz ...
- Codeforces 7C 扩展欧几里得
扩展欧几里得是计算 ax + by = gcd(a,b) 的 x,y的整数解. 现在是ax + by + c = 0; 只要 -c 是 gcd(a,b) 的整数倍时有整数解,整数解是 x = x*(- ...
- Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x·a + y·b = n】
B. Proper Nutrition time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Iris Classification on Keras
Iris Classification on Keras Installation Python3 版本为 3.6.4 : : Anaconda conda install tensorflow==1 ...
- 学习笔记 - Git
学习参考网址:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 Git是目前世界上 ...
- Spring Cloud负载均衡:使用zuul作服务器端负载均衡
1.目的: 本文简述Spring Cloud负载均衡之服务器负载均衡模式,使用组件为zuul. zuul作为Spring Cloud中的网关组件,负责路由转发.身份验证.请求过滤等等功能,那么我们可以 ...
- 阶段3 2.Spring_06.Spring的新注解_7 spring整合junit问题分析
测试类重复代码的问题 这是之前的方式 运行findAll的方法,没有问题 测试人员不需要关心上面的方法,.应该关心的各个方法是否能够正常的运行 对于一个测试工程师,只要写完变量就可以测试了. 可以使用 ...
- Maven 安装 / 常用配置 / 阿里maven中央仓库
Maven 官方下载地址: http://maven.apache.org/download.cgi 可以选择清华的镜像: 解压在settings.xml里面配置阿里中央仓库: <mirror& ...
- JAVA 内存的那些事
(转载)固然Java屏蔽了一下内存细节,但是有时候,了解一下这些常识还是有好处的,特别是一些口试,总是盯着这些玩意不放手. JVM启动以后,会分配两类内存区域,一类用于开发职员使用,比如保存一些变量, ...
- linu基础命令1
/根目录,第一级目录 1.ls列出当前目录下的文件和目录-a: 列出所有的文件,包括所有以.开头的隐藏文件-d: 列出目录本身,并不包含目录中的文件(-ld)-h: 和-l一起使用,文件大小人类易读 ...
- 通过NGINX location实现一个域名访问多个项目
location ~ \.php$ { root /home/webroot; //此目录下有多个项目 project1 ,project2... fastcgi_pass $php_upstr ...
- cocos2dx基础篇(7) 触碰事件
cocos2dx游戏引擎的重点是在于移动设备的跨平台开发,而移动设备上的游戏大部分都是通过屏幕触碰来进行的.比如主菜单的按钮触碰,打飞机中飞机的触碰移动,都需要用到触碰操作.想一想之前讲的菜单按钮CC ...
- LeetCode.922-按奇偶排序数组 II(Sort Array By Parity II)
这是悦乐书的第354次更新,第379篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第216题(顺位题号是922).给定非负整数的数组A,A中的一半整数是奇数,而剩下的一半 ...