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. android国际化操作

    1.简单介绍 我们知道在java中通过.properties文件来配置资源文件,一般用的有中文message_zh_CN.properties和英文message_en_US.properties两个 ...

  2. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室 实战系列(不断更新中)

    项目简介 利用ASP.NET SignalR技术与Layim前端im框架实现的一个简单的web聊天室,包括单聊,群聊,加好友,加群,好友搜索,管理,群组管理,好友权限设置等功能.涉及技术: Elast ...

  3. 获取本机MAC地址

    <%@ page contentType="text/html; charset=GBK" %><html><head><meta htt ...

  4. knockout+bootstrap+MVC 登录页实现

    一.环境概述 1.MVC4.0项目 2.bootstrap引入: 生产环境版本引入:在web\Content 文件夹中引入bootstrap-3.2.0-dist, 源码版本CSS引入:将bootst ...

  5. JAVA_Java常用核心包(概念)

    20150802 Created By BaoXinjian

  6. FPGA基本原理之一

    FPGA就好像一个平台,用简单的器件和复杂的逻辑构建起来的.这个平台大概由六部分组成,分别为基本可编程逻辑模块(CLB).可编程输入/输出模块(IOB).嵌入式块RAM.丰富的布线资源.底层嵌入功能单 ...

  7. Karma:2. 集成 Karma 和 mocha 进行单元测试

    上一篇文章讨论了如何集成 Karma 和 Jasmine,地址见:Karma:1. 集成 Karma 和 Jasmine 进行单元测试 这篇文章讨论如何 Karma 集成 mocha 测试框架. 安装 ...

  8. 黑盒测试与白盒测试(Black box Testing)

    黑盒测试和白盒测试的优缺点 类别 优点 缺点 黑盒测试 不需要了解软件代码 从用户角度出发 无法保证代码内各个路径被覆盖到 白盒测试 强制测试开发工程师关注代码的具体实现 揭露隐藏在代码中的Bug 是 ...

  9. AX2012 常用表关系(客户地址,联系信息)

    //客户地址信息 static void CustAddressInformation(Args _args) { CustTable custTable; DirPartyTable dirPart ...

  10. bash操作小结

    刚开始学写bash脚本,发现有很多需要注意的细节问题,在这里记录一下便于记忆: 1. help test  帮助 2. bash提供的数组数据结构,它是以数字为下标的,和C语言从0开始的下一样  参考 ...