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 - 简单数论的更多相关文章

  1. hdu 2084 数塔(简单dp)

    题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...

  2. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  3. 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 ...

  4. 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 ...

  5. Codeforces 41D Pawn 简单dp

    题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...

  6. 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 ...

  7. 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 ...

  8. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

随机推荐

  1. 64-bit Itanium与x64

    64-bit Itanium是什么意思 64-bit Itanium,指的是intel 安腾处理器,intel安腾处理器是Intel的某一代处理器,当然是在酷睿(即core)这一代之前出来的. ora ...

  2. 创建es索引-格式化和非格式化

    创建es索引-格式化和非格式化 学习了:https://www.imooc.com/video/15768 索引有结构化和非结构化的区分: 1, 先创建索引,然后POST修改mapping 首先创建索 ...

  3. android的armeabi和armeabi-v7a

    在ANE中如果SDK调用了so库,则需要把so库放到ANE下Android-ARM/lib/armeabi (调试模式)或者 armeabi-v7a(发行模式)下. 可以贴个ADT代码说明问题: // ...

  4. LeetCode——Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  5. js 日期 (10 + '').length == 10 ? '0' + 10 : 10;

    js 日期 (10 + '').length == 10 ? '0' + 10 : 10;

  6. cocos2dx 3.0打包android遇到的错误(持续更新)

    1.编译时遇到找不到文件的错误:比如fatal error: cocos-ext.h: No such file or directory    , fatal error: CocosGUI.h: ...

  7. wxWidgets刚開始学习的人导引(6)——wxWidgets学习材料清单

    wxWidgets刚開始学习的人导引全文件夹   PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wx ...

  8. VUE 之 路由 VueRouter

    1.VueRouter的安装 1.1.https://unpkg.com/vue-router/dist/vue-router.js下载安装. 1.2.<script src="./s ...

  9. MyCAT简单入门配置

    MyCAT简单入门配置 安装jdk 建议1.7以上 安装mysql 安装MyCAT Mycat 源码:https://github.com/MyCATApache/Mycat-Server Mycat ...

  10. JAVA反射改动常量,以及其局限

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/barryhappy/article/details/24442953 问题,以及一个解决方式 今天公 ...