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 ...
随机推荐
- 51nod 1611 金牌赛事
被亮亮D飞啦!!QWQ 这题明明是最大权闭合子图+线段树优化构图好不好 被迫考虑DP,并且考虑f[i]表示到第i个位置的最大值(第i个位置可选可不选) 对于最终的答案,我们可以分割成一段一段的,也就是 ...
- 如何的退出无响应的 SSH 连接
~. 具体操作是Shift+-,然后松开按.. tips如果无效,可以先按下Enter,然后进行上面的操作.
- XAML实例教程系列 - 开篇(一)
XAML实例教程系列 - 开篇 2012-05-14 11:47 by jv9, 5588 阅读, 8 评论, 收藏, 编辑 去年,曾答应银光中国论坛的朋友推出一个关于XAML语言实例教程系列,帮助学 ...
- Android Studio笔记
1. toolbar xml: <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:la ...
- sql数据库CHECKDB时报x个分配错误和x个一致性错误
--1.在SQL查询分析器中执行以下语句:(注以下所用的POS为数据库名称,请用户手工改为自己的数据库名) use pos dbcc checkdb --2.查看查询结果,有很多红色字体显示,最后结果 ...
- cookie应用(一周内免登陆)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 如何自学编程,零基础适合学习Java或者Web前端吗,非科班的能学java吗?
很多人都会选择自学Java或者前端,相信有在校的大学生,有正在上班想转行的,也有已经在自学的.下面通过几个问题我来给大家分析学习编程的难易程度. 编程是什么? 通俗的理解,编程就是编写程序,哪什么是程 ...
- html基础代码演示2
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Http协议详解(转)>>>写的很好
声明:本片文章非原创,仅供自己学习并分享 内容来源于博客园作者MIN飞翔的HTTP协议详解地址http://www.cnblogs.com/EricaMIN1987_IT/p/3837436.html ...
- vb.net实现textbox控件输入指定位数小数方法实现。
Private Sub textbox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPres ...