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. 生活娱乐 Wifi机器人的制作流程

    思路简单,但是创意无限~~ 动手能力超强 牛人教你做Wifi机器人(图) 一.前言 Wifi机器人(Wifi Robot):其实是一辆能通过互联网,或500米以外的笔记本无线设施来远程控制的遥控汽车. ...

  2. 133. Clone Graph (3 solutions)——无向无环图复制

    Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of its nei ...

  3. SQL数据分组后取最大值或者取前几个值(依照某一列排序)

    今日做项目的时候,项目中遇到须要将数据分组后,分组中的最大值,想了想,不知道怎么做.于是网上查了查,最终找到了思路,经过比較这个查询时眼下用时最快的,事实上还有别的方法,可是我认为我们仅仅掌握最快的方 ...

  4. Struts2实现空表单信息的提示

    须要的jar包文件: index.jsp源代码: <%@ page language="java" contentType="text/html; charset= ...

  5. 利用easyUI的combobox打造自己主动提示组件

    自己主动提示是时下一个非常流行的功能,比方说百度.谷歌的搜索输入框都使用到了这么一个功能. 因为easyUI的combobox设计师已经考虑到了这个功能.所以仅仅需简单几步我们能够轻松打造自己的自己主 ...

  6. java的gradle项目的基本配置

    plugins { id 'org.springframework.boot' version '2.1.4.RELEASE' id 'java' } apply plugin: 'io.spring ...

  7. InspectIT_EUM 实现原理概述

    在Git上查看 InspectIT 实现原理概述: 实现原理详解:  1.jsAgent如何注入到浏览器 通过ASM框架修改HttpService.service()方法,加入相关逻辑,对每一个Htt ...

  8. gRPC错误码 http状态码 provide your APIs in both gRPC and RESTful style at the same time

    How gRPC error codes map to HTTP status codes in the response https://github.com/grpc-ecosystem/grpc ...

  9. Ehcache CacheManager

    CacheManager是Ehcache框架的核心类和入口,它负责管理一个或多个Cache对象.要使用Ehcache框架,必须要先创建 CacheManager 对象.现在我们学习下,如何创建 Cac ...

  10. MapReduce ChainMapper/ChainReducer

    The ChainMapper class allows to use multiple Mapper classes within a single Map task.  The ChainRedu ...