A. Arpa’s hard exam and Mehrdad’s naive cheat

题意求1378的n次方的最后一位,懒的写循环节 瞎快速幂

py3 int和LL 合并为int了

 def q_(x):
a = 8
ans = 1
while(x>0):
if(x&1):
ans = ans*a%10
a = a*a%10
x = x//2
print(ans%10) c =int(input())
q_(c)

B. Arpa’s obvious problem and Mehrdad’s terrible solution

ZZ题  读题浪费了很长时间

C. Arpa's loud Owf and Mehrdad's evil plan

找环  不合法的情况肯定是度为单数的点 然后 DFS就ok  偶数/2 求lcm

 def gcd(x,y):
return x if y==0 else gcd(y,x%y)
def lcm(x,y):
return x//gcd(x,y)*y
def dfs(x,y):
if(vis[x]):
return y
vis[x] = 1
return dfs(c[x-1],y+1)
n =int(input())
c = []
for x in input().split():
c.append(int(x))
vis = [0]*(n+1)
ind = [0]*(n+1)
for i in range(n):
ind[i+1]+=1
ind[c[i]]+=1
mk = 1
for i in range(n):
if(ind[i+1]&1):
mk = 0
ans = 1
if(mk):
for i in range(n):
if(vis[i+1]==0):
val = dfs(i+1,0)
if(val%2==0):
val//=2
ans = lcm(ans,val)
print(ans)
else:
print("-1");

D. Arpa's weak amphitheater and Mehrdad's valuable Hoses

约妹纸,要么约集合,要么约集合中的一个(可用list优化) 并查集加01背包

但是问题来了...这个题做了整整五个小时没A...................  TLE到死         python的多重循环比C++慢百倍....怪不得DE这种题一般没python的出现....

优化了range  继续TLE  直到现在  我放弃了

虽然红了两页  但是学到了不少....蛮阿Q的...

n, m, w = map(int, input().split())
W = []
B = []
W = list(map(int, input().split()))
B = list(map(int, input().split()))
par = [0]*(n+10)
for i in range(0, n):
par[i] = i
def find(x):
if(x == par[x]):
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x, y):
x = find(x)
y = find(y)
if(x != y):
par[x] = y
for i in range(m):
x, y = map(int, input().split())
unite(x-1, y-1)
dp = [0]*(w+10)
q = [0]*(n+10)
for i in range(n):
if(i==find(i)):
cnt = 0
V = 0
E = 0
for k in range(n):
if(find(k)==find(i)):
q[cnt] = k
cnt += 1
V += W[k]
E += B[k]
for j in range(w,-1,-1):
if(j>=V):
dp[j] = max(dp[j],dp[j-V]+E)
for k in range(cnt):
if(j>=W[q[k]]):
dp[j] = max(dp[j],dp[j-W[q[k]]]+B[q[k]])
print(dp[w])

理论AC代码

后来去CF上拿了份代码  把python翻译成C++   就AC了

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,w,cnt;
int fa[],a[],b[],f[],q[];
int find(int x)
{
if(!fa[x]) return x;
fa[x]=find(fa[x]);
return fa[x];
}
int main()
{
int i,r1,r2,j,k;
scanf("%d%d%d",&n,&m,&w);
for(i=;i<=n;i++) scanf("%d",&a[i]);
for(i=;i<=n;i++) scanf("%d",&b[i]);
for(i=;i<=m;i++)
{
scanf("%d%d",&r1,&r2);
j=find(r1); k=find(r2);
if(j!=k)fa[k]=j;
}
for(i=;i<=n;i++)
if(fa[i]==)
{
cnt=; int ww=,bb=;
for(j=;j<=n;j++) if(find(j)==i)
{
q[++cnt]=j; ww+=a[j]; bb+=b[j];
}
for(j=w;j>=;j--)
{
//f[i][j]=f[i-1][j];
for(k=;k<=cnt;k++) if(j>=a[q[k]]) f[j]=max(f[j],f[j-a[q[k]]]+b[q[k]]);
if(j>=ww) f[j]=max(f[j],f[j-ww]+bb);
}
} printf("%d",f[w]);
return ;
}

AC代码

待补
E.

F.

Codeforces Round #383 _python作死系列的更多相关文章

  1. 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 题解 直接 ...

  2. 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 ...

  3. 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 ...

  4. dfs + 最小公倍数 Codeforces Round #383 (Div. 2)

    http://codeforces.com/contest/742/problem/C 题目大意:从x出发,从x->f[x] - > f[f[x]] -> f[f[f[x]]] -& ...

  5. 01背包dp+并查集 Codeforces Round #383 (Div. 2)

    http://codeforces.com/contest/742/problem/D 题目大意:有n个人,每个人有重量wi和魅力值bi.然后又有m对朋友关系,朋友关系是传递的,如果a和b是朋友,b和 ...

  6. Codeforces Round #383 Div 1题解

    第一次打Div 1,感觉还是挺难的..把基础题打完就日常划水了.... [A. Arpa's loud Owf and Mehrdad's evil plan](http://codeforces.c ...

  7. 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 ...

  8. Codeforces Codeforces Round #383 (Div. 2) E (DFS染色)

    题目链接:http://codeforces.com/contest/742/problem/E 题意: 有一个环形的桌子,一共有n对情侣,2n个人,一共有两种菜. 现在让你输出一种方案,满足以下要求 ...

  9. 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 ...

随机推荐

  1. Python(SQLAlchemy-ORM)模块之mysql操作

    一.SQLAlchemy简单介绍 SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数 ...

  2. ROC曲线

    1.混淆矩阵(confusion matrix)     针对预测值和真实值之间的关系,我们可以将样本分为四个部分,分别是:     真正例(True Positive,TP):预测值和真实值都为1 ...

  3. 【转载-好文】使用 Spring 2.5 注释驱动的 IoC 功能

    在 IBM Bluemix 云平台上开发并部署您的下一个应用. 开始您的试用 原文链接:https://www.ibm.com/developerworks/cn/java/j-lo-spring25 ...

  4. ios7 indexPathForCell 的坑(真是一个大大的坑)

    笔者在编写APP 有一个功能点击cell上一个button,修改cell的在tableview中的位置 在ios8上没有问题. 在ios7上总是崩溃 以下是崩溃后提示: Terminating app ...

  5. linux下的vim使用教程

    命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...

  6. JSON库之性能比较:JSON.simple VS GSON VS Jackson VS JSONP

    从http://www.open-open.com/lib/view/open1434377191317.html 转载 Java中哪个JSON库的解析速度是最快的? JSON已经成为当前服务器与WE ...

  7. Vs程序自动获取windows7/vista系统管理员权限

    1.在工程中加入MANIFEST资源(C#) 打开VS2005.VS2008.VS2010工程,查看在Properties下是否有app.manifest这个文件:如没有,按如下方式创建:鼠标右击工程 ...

  8. 算法库:boost安装配置

    前提是电脑上已经装有VS. 1. 下载boost_1_60_0.zip并解压到所需位置 2. 双击bootstrap.bat生成b2.exe(新版)和bjam.exe(老版) 3. 双击b2.exe或 ...

  9. Codeforces 721D [贪心]

    /* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...

  10. NDK 的开发流程

    1.NDK开发所需要的工具 windows 需要在windows下的环境 把c代码打包成 手机能用的函数库 首先模拟手机的环境 1 NDK .sh linux 批处理文件 .bat windows 头 ...