博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 984 扫雷check 欧几里得b进制分数有限小数判定 f函数最大连续子段
阅读量:4960 次
发布时间:2019-06-12

本文共 7022 字,大约阅读时间需要 23 分钟。

A

/* Huyyt */#include 
#define mem(a,b) memset(a,b,sizeof(a))#define mkp(a,b) make_pair(a,b)#define pb push_backusing namespace std;typedef long long ll;const long long mod = 1e9 + 7;const int N = 2e5 + 5;int num[1005];int main(){ int n; cin >> n; for(int i=1;i<=n;i++) { cin >> num[i]; } sort(num+1,num+1+n); int now=0; if(n%2) { cout<
View Code

B

/* Huyyt */#include 
#define mem(a,b) memset(a,b,sizeof(a))#define mkp(a,b) make_pair(a,b)#define pb push_backconst int dir[8][2] = {
{
0, 1}, {
1, 0}, {
0, -1}, { -1, 0}, {
1, 1}, {
1, -1}, { -1, -1}, { -1, 1}};using namespace std;typedef long long ll;const long long mod = 1e9 + 7;const int N = 2e5 + 5;char f[105][105];int n, m;bool ok(int x, int y){ if (x > n || x < 1) { return false; } if (y > m || y < 1) { return false; } return true;}int main(){ cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%s", f[i] + 1); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (f[i][j] == '*') { continue; } if (f[i][j] == '.') { for (int w = 0; w < 8; w++) { int dx = i + dir[w][0]; int dy = j + dir[w][1]; if (ok(dx, dy)) { if (f[dx][dy] == '*') { cout << "NO" << endl; return 0; } } } } else { int now = 0; int cur = f[i][j] - '0'; for (int w = 0; w < 8; w++) { int dx = i + dir[w][0]; int dy = j + dir[w][1]; if (ok(dx, dy)) { if (f[dx][dy] == '*') { now++; } } } if (now != cur) { cout << "NO" << endl; return 0; } } } } cout << "YES" << endl; return 0;}
View Code

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
#define mem(a,b) memset(a,b,sizeof(a))#define pb push_backusing namespace std;typedef long long ll;typedef unsigned long long ull;const ll LLmaxn = 2e18;const int N = 100005;int n;inline ll readint(){ char c = getchar(); ll ans = 0; while (c < '0' || c > '9') { c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10LL + c - '0', 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 = 1; i <= n; i++) { p=readint(),q=readint(),b=readint(); ll now = gcd(p, q); p /= now, q /= now; if (q == 1) { cout << "Finite" << endl; continue; } p %= q; if (p == 0) { cout << "Finite" << endl; continue; } now = gcd(q, b); while (now != 1) { while (q % now == 0) { q /= now; } now=gcd(q,b); } if (q == 1) { cout << "Finite" << endl; } else { cout << "Infinite" << endl; } }}
View Code

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
#define mem(a,b) memset(a,b,sizeof(a))#define pb push_backusing namespace std;typedef long long ll;typedef unsigned long long ull;const ll LLmaxn = 2e18;const int N = 100005;inline int readint(){ char c = getchar(); int ans = 0; while (c < '0' || c > '9') { c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0', c = getchar(); } return ans;}int number[5005];int dp[5005][5005];int main(){ int now = 0; int n; n = readint(); for (int i = 1; i <= n; i++) { number[i] = readint(); } for (int i = 1; i <= n; i++) { dp[i][i] = number[i]; } for (int len = 1; len <= n - 1; len++) { for (int i = 1; i <= n - len; i++) { dp[i][i + len] = dp[i][i + len - 1] ^ dp[i + 1][i + len]; } } for (int len = 1; len <= n - 1; len++) { for (int i = 1; i <= n - len; i++) { dp[i][i + len] = max(max(dp[i][i + len - 1], dp[i + 1][i + len]), dp[i][i + len]); } } int l, r; int q; q = readint(); while (q--) { l = readint(), r = readint(); cout << dp[l][r] << endl; }}
View Code

 

转载于:https://www.cnblogs.com/Aragaki/p/9045987.html

你可能感兴趣的文章
springboot+mybatis报错Invalid bound statement (not found)
查看>>
Linux环境下SolrCloud集群环境搭建关键步骤
查看>>
P3565 [POI2014]HOT-Hotels
查看>>
MongoDB的简单使用
查看>>
hdfs 命令使用
查看>>
prometheus配置
查看>>
【noip2004】虫食算——剪枝DFS
查看>>
java语法之final
查看>>
python 多进程和多线程的区别
查看>>
sigar
查看>>
iOS7自定义statusbar和navigationbar的若干问题
查看>>
[Locked] Wiggle Sort
查看>>
deque
查看>>
Setting up a Passive FTP Server in Windows Azure VM(ReplyCode: 227, Entering Passive Mode )
查看>>
Python模块调用
查看>>
委托的调用
查看>>
c#中从string数组转换到int数组
查看>>
数据模型(LP32 ILP32 LP64 LLP64 ILP64 )
查看>>
java小技巧
查看>>
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>