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. git log 查看版本演变历史

    1.查看git操作历史 $ git log  #git 查看git操作历史 $ git log  --oneline #git 简洁的查看git变更记录 $ git log -n4  --onelin ...

  2. 递归获取JSON内容的key-value值

    方法主体: 使用时,请在类中先声明一个Map,參数形式例如以下: JSONObject jobj = new JSONObject(JSONContent); 首次请传递jobj.

  3. Android的activity的生命周期

    activity的生命周期有四个重要的状态:活动,暂停,停止,销毁 基本的方法有:onCreate.onStart.onResume.onPause.onStop.onDestory 最经常使用的方法 ...

  4. leetcode题解||Container With Most Water问题

    problem: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate ...

  5. 一场由股票提醒助手插件引发的血案——浅入浅出 jquery autocomplete

    我没有学过前端,所以这篇文章注定要班门弄斧了. 通常,须要用到什么技术什么语言时,我才去学,学了也不一定掌握,就是记不住!所以如今明确了.学习的时候,亦或是攻克难点的时候,一定要记录下来.并不一定非要 ...

  6. c/c++中static和extern使用

    c/c++中static和extern使用 在C/C++中static和extern都能够用来修饰函数和变量,可是是有差别的. 内部函数和内部变量:仅仅能在文件内使用的函数和变量. 外部函数和外部变量 ...

  7. linux 标准i2c接口(一)

    一:I2C设备操作方式: 1.  应用程序操作法:i2c的设备的驱动可以直接利用linux内核提供的i2c-dev.c文件提供的ioctl函数接口在应用层实现对i2c设备的读写,但是在应用层使用ioc ...

  8. mysql 查询正在执行的事务以及等待锁 常用的sql语句

    使用navicat测试学习: 首先使用set autocommit = 0;(取消自动提交,则当执行语句commit或者rollback执行提交事务或者回滚)   在打开一个执行update查询 正在 ...

  9. (转载)display:inline、block、inline-block的区别

    display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度 <div& ...

  10. Springboot读取自定义的yml文件中的List对象

    Yml文件(novellist.xml)如下: novellist:   list:     - name: 笑傲江湖       type: 武侠       master: 令狐冲       a ...