Codeforces - 1033C - Permutation Game - 简单dp - 简单数论
https://codeforces.com/problemset/problem/1033/C
一开始觉得自己的答案会TLE,但是吸取徐州赛区的经验去莽了一发。
其实因为下面这个公式是 $O(nlogn)$ 的,不是 $O(n²)$ ,所以这样做是可行的。学到了新的知识。
$$\sum\limits_{i=1}^{n}\lfloor\frac{n}{i}\rfloor$$
PS:学会LaTeX啦!
#include<bits/stdc++.h>
using namespace std;
#define ll long long int res[];
int p[];
int a[]; int n;
void solve(int num,int c){
for(int k=;p[num]+k*num<=n;k++){
if(a[p[num]+k*num]>num){
if(res[a[p[num]+k*num]]==){
//存在一种转移到先手赢的情况?不应该让对方赢
//存在一种转移到先手输的情况,转移过去自己就赢了
//printf("%d can move to %d\n",num,a[p[num]+k*num]);
res[num]=;
return;
}
}
}
for(int k=;p[num]-k*num>=;k++){
if(a[p[num]-k*num]>num){
if(res[a[p[num]-k*num]]==){
//存在一种转移到先手赢的情况?不应该让对方赢
//存在一种转移到先手输的情况,转移过去自己就赢了
//printf("%d can move to %d\n",num,a[p[num]-k*num]);
res[num]=;
return;
}
}
}
} int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
p[a[i]]=i;
} res[n]=;
//先手赢=false
for(int i=n-;i>=;i--){
res[i]=;
//一开始假设没办法转移,先手赢=false
solve(i,'A');
if(res[i]==){
//printf("%d cannot move\n",i);
}
} for(int i=;i<=n;i++){
int t=a[i];
if(res[t]==){
printf("A");
}
else{
printf("B");
}
} printf("\n");
}
2019-01-16
Codeforces - 1033C - Permutation Game - 简单dp - 简单数论的更多相关文章
- hdu 2084 数塔(简单dp)
题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- Codeforces Round #302 (Div. 2) C. Writing Code 简单dp
C. Writing Code Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...
- Codeforces 41D Pawn 简单dp
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...
- Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
随机推荐
- 转:linux下ip修改与域名解析查看等
转自: http://www.justwinit.cn/post/7038/ IP: ifconfiggateway:172.16.0.254 [root@localhost ~]# nets ...
- [Javascript] Cancel A Promise Using AbortController
The AbortController interface enables us to cancel a one or more DOM requests. In this lesson, we wi ...
- 用Meta 取消流量器缓存方便调试
<!-- 禁止浏览器从本地缓存中调阅页面.--> <meta http-equiv="pragram" content="no-cache"& ...
- hunnu--11545--小明的烦恼——找路径
小明的烦恼--找路径 Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:32768KB Total submit users: ...
- linux 命令之 watch
watch能够帮你监測一个命令的执行结果,省得你一遍遍的手动执行.在Linux下.watch是周期性的执行下个程序.并全屏显示执行结果.你能够拿他来监測你想要的一切命令的结果变化,比方 tail 一个 ...
- error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
头文件函数声明少了“:(分号)”
- C++ 模板应用浅析
把曾经写的C++模板的应用心得发表出来. 回忆起当时在学习C++模板时的无助和恐惧,如今还心有余悸.我分享出来我的心得,仅仅希望别人少走弯路,事实上它就这么几种使用方法,不须要害怕. 我总结了模板的四 ...
- HTTP请求中带有特殊字符"|",返回400错误
Java平台,服务器是Tomcat8,前端ajax访问服务器时,F12返回400错误,经分析,URL地址中get传参值里面含有“|“, Invalid character found and RFC ...
- 轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- update外联表,用另一个表数据更新本表数据
update s set s.classbid = lc.itemidfrom dbo.Lv_servers as s INNER JOIN dbo.Lv_LineChannel as lc O ...