AIM Tech Round (Div. 2)——ABCD
http://codeforces.com/contest/624
A.python是用来写div2的AB题的...
a, b, x, y = map(float, raw_input().split())
print ((b - a) / (x + y))
B.思路很简单,但你的实现一样简短吗
n = input()
a = sorted(map(int, raw_input().split()))
s = 0
x = 10 ** 9
while a and x:
x = min(x, a.pop())
s += x
x -= 1
print s
C.注意到只有abc三种字符
b是和abc都相邻的!就很ok!
跟n-1个都相邻的肯定涂b
然后随便选个连b的涂成a再dfs
剩下的涂c最后检验就行
import java.util.Scanner; public class C {
static int[][] g = new int[505][505];
static char[] s = new char[505];
static int n;
static void dfs(int x) {
s[x] = 'a';
for(int i = 1;i <= n;i ++)
if(g[x][i] == 1 && s[i] == 0)
dfs(i);
}
public static void main(String []args) {
Scanner cin = new Scanner(System.in);
n = cin.nextInt();
int m = cin.nextInt();
int[] u = new int[130005];
int[] v = new int[130005];
int[] c = new int[505];
for(int i = 1;i <= m;i ++) {
u[i] = cin.nextInt();
v[i] = cin.nextInt();
g[u[i]][v[i]] = 1;
g[v[i]][u[i]] = 1;
c[u[i]] ++;
c[v[i]] ++;
}
boolean ok = false;
for(int i = 1;i <= n;i ++)
if(c[i] == n - 1) {
s[i] = 'b';
ok = true;
}
if(!ok) dfs(1);
else {
for(int i = 1;i <= n;i ++) {
if(s[u[i]] == s[v[i]] && s[u[i]] == 'b') continue;
if(s[u[i]] == 'b' || s[v[i]] == 'b') {
if(s[u[i]] == 'b') dfs(v[i]);
else dfs(u[i]);
break;
}
}
}
for(int i = 1;i <= n;i ++)
if(s[i] == 0)
s[i] = 'c';
for(int i = 1;i <= n;i ++)
for(int j = i + 1;j <= n;j ++) {
boolean x = (g[i][j] != 0);
boolean y = (s[i] == s[j] || s[i] - s[j] == 1 || s[j] - s[i] == 1);
if(x ^ y) {
System.out.println("No");
System.exit(0);
}
}
System.out.println("Yes");
for(int i = 1;i <= n;i ++)
System.out.print(s[i]);
}
}
注意也可能没有b,就选第一个点涂a,dfs下去就行了
D.显然a1,a1 + 1, a1 - 1, an, an + 1, an - 1
这六个数在最后的数列里至少出现了一个
最后数列的gcd肯定在这个数里...然后枚举这个gcd
开始DP,f[0/1/2][i]代表到第i个位置还没开始remove/正在remove/已经结束remove的最小代价
状态说清了,转移方程想一想咯
#include <bits/stdc++.h> using namespace std; const int maxn = ; typedef long long ll; int n, a, b, c[maxn], v[maxn]; ll f[][maxn], ans = 1e18; void dp(int x) {
memset(f, 0x3f3f3f3f, sizeof f);
f[][] = f[][] = f[][] = ;
for(int i = ;i <= n;i ++) {
if(c[i] % x == || c[i] % x == || c[i] % x == x - ) {
f[][i] = f[][i - ] + b * (c[i] % x != );
f[][i] = f[][i - ] + b * (c[i] % x != );
}
f[][i] = min(f[][i - ], f[][i - ]) + a;
f[][i] = min(f[][i], f[][i]);
if(f[][i] >= ans && f[][i] >= ans) return;
}
ans = min(min(f[][n], f[][n]), ans);
} void solve(int x) {
for(int i = ;i * i <= x;i ++)
if(x % i == ) {
if(!v[i]) dp(i);
v[i] = ;
while(x % i == ) x /= i;
}
if(x != ) dp(x);
} int main() {
scanf("%d %d %d", &n, &a, &b);
for(int i = ;i <= n;i ++)
scanf("%d", &c[i]);
solve(c[]), solve(c[] - ), solve(c[] + );
solve(c[n]), solve(c[n] - ), solve(c[n] + );
printf("%lld\n", ans);
return ;
}
AIM Tech Round (Div. 2)——ABCD的更多相关文章
- AIM Tech Round (Div. 1) D. Birthday 数学 暴力
D. Birthday 题目连接: http://www.codeforces.com/contest/623/problem/D Description A MIPT student named M ...
- AIM Tech Round (Div. 2) D. Array GCD dp
D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...
- AIM Tech Round (Div. 2) C. Graph and String 二分图染色
C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...
- AIM Tech Round (Div. 2) B. Making a String 贪心
B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...
- AIM Tech Round (Div. 2) A. Save Luke 水题
A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- AIM Tech Round (Div. 2) B
B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- AIM Tech Round (Div. 2) A
A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AIM Tech Round (Div. 1) C. Electric Charges 二分
C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...
随机推荐
- XAML实例教程系列 - 资源(Resources)
Kevin Fan分享开发经验,记录开发点滴 XAML实例教程系列 - 资源(Resources) 2012-08-10 12:47 by jv9, 1386 阅读, 1 评论, 收藏, 编辑 在Wi ...
- 【Hibernate总结系列】使用举例
本节讲述如何使用Hibernate实现记录的增.删.改和查功能. 1 查询 在Hibernate中使用查询时,一般使用Hql查询语句. HQL(Hibernate Query Language),即H ...
- J20170916-hm
スタイルシート 样式表 シール 封条 シート 纸片 マニフェスト 货单(Rails) ダイジェスト 消化,(Rails 附加哈希值) インタプリタ n. 解释者; 口译译员; [军事] 判读员; [自 ...
- codevs1369 xth 砍树(线段树)
1369 xth 砍树 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在一个凉爽的夏夜,xth 和 rabbi ...
- 2019 年了,为什么我还在用 jQuery?
译者按: 看来 jQuery 还是有一些用武之地的. 原文: Why I'm Still Using jQuery in 2019 译者: Fundebug 为了保证可读性,本文采用意译而非直译.翻译 ...
- easyui -tree的详细讲解
代码的具体实现 @{ ViewBag.Title = "人员查找"; ViewBag.LeftWidth = "200px"; ViewBag ...
- cobbler+kickstart安装笔记
cobbler+kickstart安装笔记 本文参考老男孩配置:https://blog.oldboyedu.com/autoinstall-cobbler/ centos7:开机如果不启动网卡,需要 ...
- Objective-C copy(转)
一.从面向对象到Objective-C概览copy 1.面向对象: In object-oriented programming, object copying is creating a copy ...
- 使用Jquery.form.js ajax表单提交插件弹出下载提示框
现象: 使用jquery的from做ajax表单提交的时候,后台处理完毕返回json字符串,此时浏览器提示下载一个json文件而不是在success里面继续解析该json对象. 具体的原因: 浏览器兼 ...
- Laravel5.1学习笔记18 数据库4 数据填充
简介 编写数据填充类 使用模型工厂类 调用额外填充类 执行填充 #简介 Laravel includes a simple method of seeding your database with t ...