【AtCoder Regular Contest 082】Derangement

【链接】点击打开链接


【题意】


在这里写题意

【题解】


贪心。
连续一块的p[i]==i的话,对答案的贡献就应该为(这个连续块的长度+1)/2;
长度为1的也正确.
(也即两两相邻的互换位置。)

【错的次数】


0

【反思】


在这了写反思

【代码】

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
#include <bitset>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long doubletypedef pair<int,int> pii;
typedef pair<LL,LL> pll;//mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;int n,p[N+10];int main(){//Open();//Close();ri(n);rep1(i,1,n) ri(p[i]);int ans = 0;rep1(i,1,n){if (p[i]!=i){continue;}int j = i;while (j+1<=n && p[j+1]==(j+1)){j++;}ans+=(j-i+1+1)/2;i = j;}oi(ans);puts("");return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626054.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/428703.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1618D. Array and Operations

D. Array and Operations&#xff1a;题目 之前写的了&#xff0c;直接上答案&#xff01; #include <bits/stdc.h> #define int long long #define pII pair<int, int> #define endl "\n" #define fast ios_base::sync_with_stdio(0), cin.tie(0), cou…

kendo 服务端排序

z折腾了一天。。 参考 &#xff1a;https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.sortable.compare 关键代码 parameterMap: function(data, type) {if(data.sort) {var sortObj data.sort[0];typeSort sortObj.dir;typeName sortObj.f…

416B. Art Union

B. Art Union&#xff1a;题目 思路&#xff1a;dp那味道来了#include <bits/stdc.h> using namespace std; typedef long long ll; vector<ll> a((int)6e5); vector<ll> b((int)6e5); int g[50051][11]; int main() {int m,n;//画的数量&#xff0c;和画家…

Windows下编译TensorFlow1.3 C++ library及创建一个简单的TensorFlow C++程序

由于最近比较忙&#xff0c;一直到假期才有空&#xff0c;因此将自己学到的知识进行分享。如果有不对的地方&#xff0c;请指出&#xff0c;谢谢&#xff01;目前深度学习越来越火&#xff0c;学习、使用tensorflow的相关工作者也越来越多。最近在研究tensorflow线下采用 pytho…

665C. Simple Strings

C. Simple Strings&#xff1a;题目 思路&#xff1a;简单的离谱&#xff0c;就相同就换就行&#xff0c;哪有dp的事啊#include <bits/stdc.h> using namespace std; typedef long long ll; vector<ll> a((int)6e5); vector<ll> b((int)6e5); string str; i…

798B. Mike and strings

B. Mike and strings&#xff1a;题目 思路&#xff1a;纯暴力题&#xff0c;不想写&#xff0c;copy了别人代码#include<iostream> #include<string> using namespace std; void change(string &s){ss.substr(1)s.substr(0,1); } int main(){int n;cin>&g…

jquery ajax 数据传输

在 form表单中&#xff0c;需要发送给后台的是一串长数据&#xff0c;后台才能接受&#xff0c;而用户则只需要输入字符串中的一部分&#xff0c;这种情况下&#xff0c;就需要将用户输入内容&#xff0c;和剩余部分进行拼串&#xff0c;然后添加进 formData 中传输。另一种情况…

1315B. Homecoming

B. Homecoming&#xff1a;题目 思路&#xff1a;从后往前遍历就行了#include <bits/stdc.h> using namespace std; typedef long long ll; vector<ll> a((int)6e5); vector<ll> b((int)6e5); string str; int main() {int t;cin >> t;while (t--){in…

jquery datatable 获取当前分页的数据

使用jquery datatable 遇到分页分别求和时&#xff0c;找了半天才找到获取当前分页数据的方法&#xff0c;以此总结 var table$(#example).DataTable( {"pagingType": "full_numbers",} ); table.columns({page:current}).data();//当前页面里的数据 转载于…

870C. Maximum splitting

C. Maximum splitting&#xff1a;题目 这凭啥1300分&#xff1f;#include <bits/stdc.h> using namespace std; typedef long long ll; vector<ll> a((int)6e5); vector<ll> b((int)6e5); string str; int main() {int t;cin>>t;while (t--){int n;c…

useGeneratedKeys的用法

<!-- useGeneratedKeys"true"把新增加的主键赋值到自己定义的keyProperty&#xff08;id&#xff09;中 --> <insert id"insert" useGeneratedKeys"true" keyProperty"id" parameterType""> 转载于:https://www…

1040B. Shashlik Cooking

B. Shashlik Cooking&#xff1a;题目 思路&#xff0c;如果所有烤肉都可以一次就行&#xff0c;如果不行就去前面调整一下#include <bits/stdc.h> using namespace std; typedef long long ll; vector<ll> a((int)6e5); vector<ll> b((int)6e5); int main(…

粉红小猪中有一个叫“快乐小鸡”的游戏

最近在学习svg,书看了一本 然后再找了个框架 snap.svg 摸索着写了个游戏给女儿玩。哈哈。即涨知识又娱乐。 转载于:https://www.cnblogs.com/goldli/p/7649898.html

626B. Cards

B. Cards&#xff1a;题目 竟然需要按照顺序输出&#xff0c;淦&#xff01;#include <bits/stdc.h> using namespace std; typedef long long ll; vector<ll> a((int)6e5); vector<ll> b((int)6e5); string str; int main() {int a 0, b 0, c 0;int n;c…

gcc 4.9编译

参考 http://blog.csdn.net/hzhxxx/article/details/28634893转载于:https://www.cnblogs.com/rabitvision/p/7650706.html

234C. Weather

C. Weather:题目 为什么直接交代码不行啊&#xff0c;非要加两句话&#xff0c;有没有大佬说说&#xff1f;#include <bits/stdc.h> using namespace std; // typedef long long ll; vector<int> a((int)3e5); vector<int> b((int)3e5), c((int)3e5); int m…

idea .defaultMessage

idea .defaultMessage 等同于eclipse里的getDefaultMessage idea只能能获取到bean设置NotBlank等message响应到jsp的key&#xff0c;不能在jsp里获取validationMessage properties文件里的value 那么我们就不要value只要key 转载于:https://www.cnblogs.com/duneF/p/7654780.h…

653B. Bear and Compressing

B. Bear and Compressing&#xff1a;题目 纯纯暴力DFS&#xff0c;和dp有啥关系&#xff01;不想写了&#xff0c;copy一份&#xff0c;写的真精简。#include <bits/stdc.h> using namespace std; int n, m; string a[40], b[40]; int f[10][10][2];int dfs(int pos, i…

【vue系列之二】详解vue-cli 2.0配置文件

上次给大家分享的是用vue-cli快速搭建vue项目&#xff0c;虽然很省时间和精力&#xff0c;但想要真正搞明白&#xff0c;我们还需要对其原理一探究竟。 大家拿到一个项目&#xff0c;要快速上手&#xff0c;正确的思路是这样的&#xff1a; 首先&#xff0c;如果在项目有readme…

698A. Vacations

A. Vacations&#xff1a;题目 题意&#xff1a;每天有四种可能性&#xff0c;锻炼和比赛分别两种可能性相乘。不能连续锻炼或者连续比赛&#xff0c;问最少休息几天。 思路&#xff1a;dp或者贪心都行。贪心写法 #include <bits/stdc.h> using namespace std; vector&…