7.15 N,O,P,Q Codeforces 691 A,B,C,D
来源:互联网 发布:激光slam算法 编辑:程序博客网 时间:2024/05/16 18:26
N - Fashion in Berland
题意:一道水题。
思路:简单模拟。
代码:
#include <iostream>using namespace std;int n;int main(){ cin>>n; if(n==1){ cin>>n; cout<<(n==0?"NO":"YES")<<endl; } else{ int c,cnt=0; for(int i=0;i<n;i++){ cin>>c; if(c==0) cnt++; if(cnt>1) {cout<<"NO"<<endl;return 0;} } cout<<(cnt==0?"NO":"YES")<<endl; } return 0;}
O - s-palindrome
题意:判断一段字符串是镜像回文串或不是。
思路:使用镜像字符数组。
代码:
思路:用并查集维护可交换的位置,用集合维护处于同一并查集的元素。每次从后往前从集合中取出元素。
代码:
#include <bits/stdc++.h>using namespace std;const int maxn=1000001;set<int> S[maxn];int p[maxn],a[maxn],n,m;int find(int x){return p[x]==x?x:p[x]=find(p[x]);}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); p[i]=i; } for(int i=1;i<=m;i++){ int x,y,fx,fy; scanf("%d%d",&x,&y); fx=find(x); fy=find(y); if(fx!=fy) p[fx]=fy; } for(int i=1;i<=n;i++){ S[find(i)].insert(a[i]); } for(int i=1;i<=n;i++){ printf("%d ",*S[find(i)].rbegin()); S[find(i)].erase(*(S[find(i)].rbegin())); } return 0;}
0 0
- 7.15 N,O,P,Q Codeforces 691 A,B,C,D
- 如果令 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 分别等于
- Cannot find or open the PDB file解决方案
- C r e a t e P r o c e s s的b I n h e r i t H a n d l e s参数
- 在O(n^2)内寻找矩阵A中 A(c,d) - A(a,b) 的最大值, c > a 且 d > b.
- printf("%d%d%d%d\n", a,b,c);
- (a+b+c+d+....)^n
- 若有以下定义,且0<=i<4,则不正确的赋值语句是 int b[4][6],*p,*q[4]; A q[i]=b[i]; B p=b; C p=b[i]; D q[i]=&b[0][0];
- codeforces 239 (div2) A B C D
- codeforces 208(div2) A+B+C+D
- codeforces 445 A、B、C、D
- codeforces 250 div2 A B C D
- CodeForces 412(A,B,C,D,E)
- Codeforces Round #351 A B C D
- codeforces 723 A,B,C,D
- Codeforces Round #377 A.B.C.D
- codeforces 817 A B C D
- linux系统编程,常见系统函数【 o p e n、 r e a d、 w r i t e、 lseek 、c l o s e】
- Ubuntu 16.04LTS+NVIDIA@GT620M+CUDA6.5环境搭建总结
- 关于GCD的学习笔记
- HDU 5873 Football Games(签到题)——2016 ACM/ICPC Asia Regional Dalian Online
- Tomcat 类加载器结构
- C语言 顺序表的实现(静态)
- 7.15 N,O,P,Q Codeforces 691 A,B,C,D
- Leetcode 257 -- Binary Tree Paths
- 设计模式(GOF)之我见(1)——Factory
- 【Qt开发】Qt应用程序发布封装
- hdu5875 Function (预处理+单调性质)
- iOS开发 - Quartz2D绘图
- 【算法学习】纯高斯模糊算法处理灰度图片
- 【BLE-CC2640】CC2640之微信硬件快速入门
- 快速排序(quicksort)