Educational Codeforces Round 14
水
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int a[];
int main(){
int n;
cin>>n;
int k=;
for(int i=;i<n;i++){
cin>>a[i];
if(!a[i]) k++;
}
if(n==&&a[]==){
puts("NO");
exit();
}
if(n==&&a[]==){
puts("YES");
exit();
}
if(k==) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}
题意:判断是否是 ‘镜像‘
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
std::pair<char, char> mapP[] ={{'A', 'A'}, {'b', 'd'}, {'d', 'b'}, {'H', 'H'}, {'I', 'I'}, {'M', 'M'}, {'O', 'O'}, {'o', 'o'}, {'p', 'q'},
{'q', 'p'},{'T', 'T'}, {'U', 'U'}, {'V', 'V'}, {'v', 'v'},{'W', 'W'}, {'w', 'w'}, {'X', 'X'}, {'x', 'x'}, {'Y', 'Y'}
}; bool check(char a, char b){
for(std::pair<char, char> p : mapP){
if(p.first == a && p.second == b){
return true;
}
}
return false;
} int main(){
string s;
cin>>s;
int i,j;
bool flag=false;
for(i=,j=(int)s.length()-;i<=j;i++,j--){
if(!check(s[i],s[j])){
flag=;
puts("NIE");
break;
}
}
if(!flag)
puts("TAK");
return ;
}
题意:把一个值转换成 表达式a*10^b形式
字符处理
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int main(){
string s;
string str="";
int ansb;
cin>>s;
int p=;
while(p<(int)s.size()&&(s[p]==''||s[p]=='.')){
p++;
}
// cout<<p<<bndl;
str.push_back(s[p]);
str.push_back('.');
int pos=s.find('.');
if(pos==-) pos=s.size();
for(int i=++p;i<s.size();i++){
if(s[i]!='.') str.push_back(s[i]);
}
if(pos==p) ansb=;
else{
if(pos>p) ansb=pos-p;
else ansb=pos-p+;
}
while(str.back()==''||str.back()=='.') str.pop_back();
if(ansb) str+="E"+to_string(ansb);
printf("%s\n",str.c_str());
return ;
}
题意:n个数(1,2。。。n) m种操作:交换下标为x y的数, 每种操作可选任意次,输出最大字典序。
思路:并查集。最后把每个位置上同一个块的从大到小输出
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int a[N];
int pre[N];
vector<int>ans[N];
vector<int>root;
int vis[N];
int pos[N];
int find(int x){
if(x==pre[x]) return x;
return pre[x]=find(pre[x]);
}
int main(){
std::ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>a[i];
pre[i]=i;
}
while(m--){
int x,y;
cin>>x>>y;
x=find(x),y=find(y);
if(x!=y) pre[x]=y;
}
for(int i=;i<=n;i++){
int x=find(i);
ans[x].push_back(a[i]);
if(!vis[x]){
root.push_back(x);
vis[x]=true;
}
}
for(int i=;i<(int)root.size();i++){ //从大到小排序
sort(ans[root[i]].rbegin(),ans[root[i]].rend());
}
for(int i=;i<n;i++){
cout<<ans[find(i)][pos[find(i)]++]<<" ";
}
cout<<ans[find(n)][pos[find(n)]]<<endl;
return ;
}
题意:n个数,选k个出来,形成一个新的序列,该序列相邻两个数异或后数的二进制中1的个数是3的倍数。问有几个序列
思路:每个数转化成一个点,两个数满足 异或后数的二进制1的个数是3倍数的则两点之间建一条边。转化成求边的条数。
矩阵快速幂
M(i,j):(ai^aj)%3==0 则最后答案是M^(k-1)的元素和
借鉴了Q神的模板
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } struct Matrix{
LL a[][];
Matrix(){
clc(a,);
}
void init(){
for(int i=;i<;i++) a[i][i]=;
}
Matrix operator * (const Matrix &B)const{
Matrix C;
for(int i=;i<;i++){
for(int k=;k<;k++){
for(int j=;j<;j++){
(C.a[i][j]+=a[i][k]*B.a[k][j])%=MOD;
}
}
}
return C;
}
Matrix operator ^ (const LL &t) const{
Matrix A= (*this),res;
res.init();
LL p=t;
while(p){
if(p&) res=res*A;
A=A*A;
p>>=;
}
return res;
}
};
LL a[];
int main(){
LL n,k;
scanf("%I64d%I64d",&n,&k);
for(int i=;i<n;i++){
scanf("%I64d",&a[i]);
}
Matrix A;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(__builtin_popcountll(a[i]^a[j])%==)
A.a[i][j]=;
}
}
LL ans=;
A=A^(k-);
for(int i=;i<n;i++){
for(int j=;j<n;j++){
(ans+=A.a[i][j])%=MOD;
}
}
printf("%I64d\n",ans);
return ;
}
题意:n个数,任选两个相乘,q次询问,每次输出不小于x的乘积对数
思路:总的方案数-小于x
预处理每种面积的方案数
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = *1e6+;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int cnt[N];
int maxn=*1e6;
LL a[N];
LL sum[N];
void init(){
for(int i=;i<=maxn;i++){
for(int j=;j*i<=maxn;j++){
if(i==j) a[i*j]+=(LL)cnt[i]*(cnt[i]-);
else a[i*j]+=(LL)cnt[i]*cnt[j];
}
}
for(int i=;i<=maxn;i++){
sum[i]=sum[i-]+a[i];
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
int x;
scanf("%d",&x);
if(x<=maxn)
cnt[x]++;
}
init();
int q;
scanf("%d",&q);
while(q--){
int x;
scanf("%d",&x);
LL ans=(LL)n*(n-)-sum[x-];
printf("%I64d\n",ans);
}
return ;
}
Educational Codeforces Round 14的更多相关文章
- Educational Codeforces Round 14 D. Swaps in Permutation (并查集orDFS)
题目链接:http://codeforces.com/problemset/problem/691/D 给你n个数,各不相同,范围是1到n.然后是m行数a和b,表示下标为a的数和下标为b的数可以交换无 ...
- Educational Codeforces Round 14 D. Swaps in Permutation(并查集)
题目链接:http://codeforces.com/contest/691/problem/D 题意: 题目给出一段序列,和m条关系,你可以无限次互相交换这m条关系 ,问这条序列字典序最大可以为多少 ...
- Educational Codeforces Round 14 D. Swaps in Permutation 并查集
D. Swaps in Permutation 题目连接: http://www.codeforces.com/contest/691/problem/D Description You are gi ...
- Educational Codeforces Round 14 C. Exponential notation 数字转科学计数法
C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are gi ...
- Educational Codeforces Round 14 B. s-palindrome 水题
B. s-palindrome 题目连接: http://www.codeforces.com/contest/691/problem/B Description Let's call a strin ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Educational Codeforces Round 14 - F (codeforces 691F)
题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围: ...
- Educational Codeforces Round 14 E.Xor-sequences
题目链接 分析:K很大,以我现有的极弱的知识储备,大概应该是快速幂了...怎么考虑这个快速幂呢,用到了dp的思想.定义表示从到的合法路径数.那么递推式就是.每次进行这样一次计算,那么序列的长度就会增加 ...
- Educational Codeforces Round 14 D. Swaps in Permutation
题目链接 分析:一些边把各个节点连接成了一颗颗树.因为每棵树上的边可以走任意次,所以不难想出要字典序最大,就是每棵树中数字大的放在树中节点编号比较小的位置. 我用了极为暴力的方法,先dfs每棵树,再用 ...
随机推荐
- 如何配置JAVA的环境变量、Tomcat环境变量
配置JAVA环境变量 1.右击[我的电脑]---[属性]-----[高级]---[环境变量],如图: 2.选择[新建系统变量]--弹出“新建系统变量”对话框,在“变量名”文本框输入“JAVA_HOME ...
- Google的Java编程风格指南(Java编码规范)
这份文档是Google Java编程风格规范的完整定义.当且仅当一个Java源文件符合此文档中的规则, 我们才认为它符合Google的Java编程风格. 与其它的编程风格指南一样,这里所讨论的不仅仅是 ...
- Git教程之管理修改(6)
Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件.你会问,什么是修改?比如你新增了一行,这就是一个修改,删除了一行,也是一个修改,更改了某些字符,也是一个修改,删了一些又加了 ...
- 48. Rotate Image
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- 离线应用Application Cache详解
特点: 1.离线可访问 - 没有网络仍可访问整个应用 2.很小的服务器负载 - 缓存在本地,不需要到服务器请求 3.高速 ...
- 函数lock_rec_bitmap_reset
/*********************************************************************//** Resets the record lock bi ...
- poi2012完成
终于完成了(2798是我cheat的……),感觉poi的题好锻炼智商…… 截图留念,题解见博客中对应题号的解题报告
- POJ 3080 (字符串水题) Blue Jeans
题意: 找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个. 分析: 用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀. #include <cstdio> ...
- UVa 10652 (简单凸包) Board Wrapping
题意: 有n块互不重叠的矩形木板,用尽量小的凸多边形将它们包起来,并输出并输出木板总面积占凸多边形面积的百分比. 分析: 几乎是凸包和多边形面积的裸题. 注意:最后输出的百分号前面有个空格,第一次交P ...
- Jquery 模板插件 jquery.tmpl.js 的使用方法(1):基本语法,绑定,each循环,ajax获取json数据
jquery.tmpl.js 是一个模板js ,主要有2个方法 (1):$.template()方法,将一段script或者是Html编译为模板,例如 $.template('myTemplate' ...