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 ...
随机推荐
- poj 2154 Color < 组合数学+数论>
链接:http://poj.org/problem?id=2154 题意:给出两个整数 N 和 P,表示 N 个珠子,N种颜色,要求不同的项链数, 结果 %p ~ 思路: 利用polya定理解~定理内 ...
- r testifying that your code will behave as you intend.
https://github.com/stretchr/testify Testify - Thou Shalt Write Tests Go code (golang) set of pack ...
- tomcat服务器配置java堆内存大小
我用的是绿色免安装的tomcat,找到tomcat下的bin文件夹下的catalina.bat文件: 编辑该文件,编辑参数,没有的话手动加上: set JAVA_OPTS=-server -Xms51 ...
- 【C语言天天练(十九)】restrict关键词
引言:在内核的系统调用函数里,常常遇到函数的參数使用restrict限定词限定的情况,以下就对该关键词做个总结. 1.restrict关键词是C99特性才加入的,因此在编译使用含有该限定词的程序时,一 ...
- JS中奇葩的假值
JavaScript中有 6 个值为“假”,这六个值是 false null undefined 0 '' (空字符串) NaN 这里面 false 本身是布尔类型,其它 5 个则不是. 除了这 6 ...
- user版本如何永久性开启adb 的root权限【转】
本文转载自:http://blog.csdn.net/o0daxu0o/article/details/52933926 [Solution]* adb 的root 权限是在system/core/a ...
- HDU3605 Escape —— 二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- ffplay 一些好玩的filter
添加字幕:ffplay -vf drawtext="fontfile=arial.ttf: text='Test Text': x=100: y=300: \ fontsize=48: fo ...
- git bash使用端口转发连接服务器
之前的配置是 url = user@xx.xx.xx.xx:/home/tutu/thelib/ww.git xx.xx.xx.xx是服务器的外网地址,其内网地址是zz.zz.zz.zz 但是现在服务 ...
- MongoDB分析工具之三:db.currentOp()
db.currentOp() db.currentOp是个好东西,顾名思义,就是当前的操作.在mongodb中可以查看当前数据库上此刻的操作语句信息,包括insert/query/update/rem ...