Codeforces Round #383 【总结】
总结一下这场。。。
搞起大号就崩了。。。
A题没啥问题。。通过电脑到手机上提交没啥大问题;
B题,讲个最严重的问题,也是最近以来最严重的问题,虽然我说你开了个数组,虽然这个数组是不是最终的答案数组,但是。。还是要考虑这个数组的范围啊,就像图的题目你为啥要注意邻接表结构体数组的大小啊,而且很恶心的是返回的是WA,而不是RE...注意每个变量的数据范围!!!还有就是题目注意点不搞好,i < j 啊!!!哎,wa11wa的整场心态崩掉。。然后C;
C题,本身因为CF卡爆不想打了,呵,CF卡爆是借口吧,主要还是心态。C知道题意,B还不知道pp没...然后C题直接乱搞,直接套强连通。。。虽然是可行的。。然而没求LCM。。。又是题意问题。。F**K! 好吧,D,E后来也没读。。。
打大号感觉真的是好烦,好多次都崩掉。。。都大二第一学期快过去了,还那么菜啊。。。。。。
--------------------------------------------------------
A题:
简单题,好像被HACK0的时候蛮多的,快速幂刚好完美躲避了。。。;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f; const int mod=10; int cal(int g,int x)
{
int ans=1;
while(g)
{
if(g&1)
ans=ans*x%mod;
x=x*x%mod;
g/=2;
}
return ans;
} int main()
{
int n;
scanf("%d",&n);
printf("%d\n",cal(n,8));
return 0;
}
B题:
a^b=c;a^c=b;b^c=a;
求个对数,而且是 i < j,ans还会爆LL;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f; const int N=1e5+10; int n,x;
int a[N];
LL num[5000050];
map<PII,int>mp; int main()
{
scanf("%d%d",&n,&x);
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
num[a[i]]++;
}
int xx,yy;
LL ans=0;
mp.clear();
for(int i=1;i<=n;i++)
{
xx=a[i];
yy=a[i]^x;
if(xx>yy)
swap(xx,yy);
if(mp[{xx,yy}]==0)
{
if(xx!=yy)
ans+=num[xx]*num[yy];
else
ans+=(num[xx]-1)*num[xx]/2;
mp[make_pair(xx,yy)]=1;
}
}
printf("%I64d\n",ans);
return 0;
}
C题:
直接套的是强连通,强连通分量元素只有一个的话且a[u]!=u那就是不满足,然后其实对每个点只有一条边,DFS一下也可以;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f; int n;
const int N=1e4+10;
const int M=5e4+10; struct Node{
int to;
int next;
};
Node edge[M]; //链式前向星
int tol,head[M]; //dfn[v]: 顶点v被访问的时间;
//low[v]: 与顶点v邻接的未删除的顶点u的low[u]和low[v]的最小值,初始时low[v]=dfn[v];
//tp: 访问时间;
//Stack[] : 数组模拟栈,p: 栈的大小;
//vis[]: 顶点是否在栈中
//in[]: 缩点后的数组,cnt: 缩点后图中点的个数
//kt[]: 出度数组
int dfn[N],low[N],tp;
int Stack[N],p;
bool vis[N];
int in[N],cnt;
int kt[N];
int a[N]; int LCM(int xx,int yy)
{
return (xx*yy/__gcd(xx,yy));
} void add(int u,int v)
{
edge[tol].to=v;
edge[tol].next=head[u];
head[u]=tol++;
} void init()
{
//初始化链式前向星
tol=0;
memset(head,-1,sizeof(head));
memset(vis,0,sizeof(vis)); //初始化顶点都不在栈里面
memset(dfn,0,sizeof(dfn)); //初始化访问时间为0
tp=p=0; //初始化时间和栈大小都为0
cnt=0; //缩点初始化,可以理解有cnt种点集
}
int flag;
int ans;
void Tarjan(int u)
{
int v;
dfn[u]=low[u]=++tp; //初始化dfn=low=访问时间 尤其注意这个++tp还是tp++,我们初始化时间是0,所以之后访问到的时间就一定>0;
Stack[++p]=u; //节点入栈
vis[u]=true; //入栈标记 for(int i=head[u];i!=-1;i=edge[i].next)
{
v=edge[i].to;
if(!dfn[v]) //如果还为被访问
{
Tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]) //在栈里;
low[u]=min(low[u],dfn[v]);
}
int temp;
int temp_num=0;
if(dfn[u]==low[u]) //如果是这个强连通分量的根;
{
cnt++; //缩点标记
while(1)
{
++temp_num;
temp=Stack[p]; //取元素
vis[temp]=false; //出栈标记
in[temp]=cnt; //缩点
--p;
if(temp==u) //如果与u相等,退出
break;
}
if(temp_num==1)
{
if(a[u]!=u)
flag=false;
}
if(temp_num%2==0)
temp_num/=2;
ans=LCM(ans,temp_num);
}
} int main()
{
int x;
scanf("%d",&n);
init();
int flagflag=false;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
a[i]=x;
if(x!=i)
flagflag=1;
add(i,x);
}
if(!flagflag)
{
puts("1");
return 0;
}
flag=true;
ans=1;
for(int i=1;i<=n;i++)
{
if(!dfn[i]) //如果还没有被访问过
Tarjan(i);
}
if(!flag)
{
puts("-1");
return 0;
}
printf("%d\n",ans);
return 0;
}
Codeforces Round #383 【总结】的更多相关文章
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
- Codeforces Round #383 (Div. 2) C. Arpa's loud Owf and Mehrdad's evil plan —— DFS找环
题目链接:http://codeforces.com/contest/742/problem/C C. Arpa's loud Owf and Mehrdad's evil plan time lim ...
- Codeforces Round #383 (Div. 2) A,B,C,D 循环节,标记,暴力,并查集+分组背包
A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 ...
- dfs + 最小公倍数 Codeforces Round #383 (Div. 2)
http://codeforces.com/contest/742/problem/C 题目大意:从x出发,从x->f[x] - > f[f[x]] -> f[f[f[x]]] -& ...
- 01背包dp+并查集 Codeforces Round #383 (Div. 2)
http://codeforces.com/contest/742/problem/D 题目大意:有n个人,每个人有重量wi和魅力值bi.然后又有m对朋友关系,朋友关系是传递的,如果a和b是朋友,b和 ...
- Codeforces Round #383 Div 1题解
第一次打Div 1,感觉还是挺难的..把基础题打完就日常划水了.... [A. Arpa's loud Owf and Mehrdad's evil plan](http://codeforces.c ...
- Codeforces Round #383 (Div. 2)C. Arpa's loud Owf and Mehrdad's evil plan
C. Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 me ...
- Codeforces Codeforces Round #383 (Div. 2) E (DFS染色)
题目链接:http://codeforces.com/contest/742/problem/E 题意: 有一个环形的桌子,一共有n对情侣,2n个人,一共有两种菜. 现在让你输出一种方案,满足以下要求 ...
- Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses —— DP(01背包)
题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable ...
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或
题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...
随机推荐
- bb=Discuz与 Discuz! X ,Discuz!NT区别
没加x的,仅仅是单独的论坛. 加了x的,模块加了很多了,门户,家园,排行榜,群组,都是Discuz! X上的,而Discuz!上没有,所以说Discuz! X更加适用于建设门户网 Discuz! X ...
- Hive调优实战
Hive是将符合SQL语法的字符串解析生成可以在Hadoop上执行的MapReduce的工具. 使用Hive尽量按照分布式计算的一些特点来设计sql,和传统关系型数据库有区别,所以需要去掉原有关系型数 ...
- 自译Solr in action中文版
文件夹 Part 1 初识 SOLR 1 Solr 简单介绍 2 開始熟悉 Solr 3 Solr 核心概念 4 配置 Solr 5 建立索引 6 文本分析 Part 2 Solr 核心功能 7 发起 ...
- Scrapyd部署
从github(https://github.com/scrapy/scrapyd)下载安装包放到D:\python\Lib\site-packages\ 解压压缩包:cd 到解压目录 python ...
- Android笔记之平移View
方法有多种,只讲一种 使用View.setLeft和View.setRight 对于wrap_content的View,要横向平移,setRight是必要的,否则View的宽度会被改变(right应设 ...
- DuiLib笔记之自定义标题栏以及响应按钮点击事件
在博文DuiLib笔记,基于WindowImplBase的基础模板的基础上,修改皮肤文件如下 <?xml version="1.0" encoding="utf-8 ...
- 区块链+AI将给区块链带来怎样的改变?
区块链和人工智能技术都是互联网时代最新.最热的技术,不仅可以改变我们生活,还能产生巨大的财富,为此国家大力支持发展,科技巨头们也纷纷布局.那区块链与人工智能结合,对区块链技术而言会产生什么样的化学反应 ...
- CAN协议与CANOpen协议
这里详细介绍了CAN协议中数据通信帧每位的含义,有图片,值得一看:https://www.cnblogs.com/pejoicen/p/3986587.html 这里介绍了CanOpen协议,http ...
- [数据挖掘课程笔记]人工神经网络(ANN)
人工神经网络(Artificial Neural Networks)顾名思义,是模仿人大脑神经元结构的模型.上图是一个有隐含层的人工神经网络模型.X = (x1,x2,..,xm)是ANN的输入,也就 ...
- Vue的watch和computed属性
Vue的watch属性 Vue的watch属性可以用来监听data属性中数据的变化 <!DOCTYPE html> <html> <head> <meta c ...