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 ...
随机推荐
- python 循环高级用法 [expression for x in X [if condition] for y in Y [if condition] ... for n in N [if condition] ]按照从左至右的顺序,分别是外层循环到内层循环
高级语法 除了像上面介绍的 [x ** 2 for x in L] 这种基本语法之外,列表推导式还有一些高级的扩展. 4.1. 带有if语句 我们可以在 for 语句后面跟上一个 if 判断语句,用于 ...
- ASP.NET SignalR Hubs API Guide - JavaScript Client
https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript- ...
- luogu 1045 麦森数
题目大意: 从文件中输入P(1000<P<3100000),计算2^P−1的位数和最后500位数字(用十进制高精度数表示) 思路: 一道高精度练习题 其中位数是一个结论 位数=[P*log ...
- codeforces 939F 单调队列优化dp
F. Cutlet time limit per test 4 seconds memory limit per test 256 megabytes input standard input out ...
- Android.mk添加第三方jar包(转载)
转自:www.cnblogs.com/hopetribe/archive/2012/04/23/2467060.html LOCAL_PATH:= $(call my-dir)include $(CL ...
- Visual Studio Code配置GitHub(Win7环境)
一.软件环境说明(演示环境) 1.操作系统:Windows7旗舰版(64bit) 2.Visual Studio Code版本:1.32.3 3.Git版本:2.21.0.windows.1 二.软件 ...
- myeclipse配置tomcat后,无法正常使用的问题
如图所示:一定要设置为Enable.否则部署tomcat时,没有tomcat8.0
- JavaScript的相关知识
Oject.assign() // Cloning an object var obj = { a: 1 }; var copy = Object.assign({}, obj); conso ...
- java攻城狮之路--复习xml&dom_pull编程
xml&dom_pull编程: 1.去掉欢迎弹窗界面:在window项的preferences选项中输入“configuration center” 找到这一项然后 把复选框勾去即可. ...
- day11-函数对象、名称空间和作用域
目录 函数对象 函数的嵌套 名称空间和作用域 内置名称空间 全局名称空间 局部名称空间 作用域 全局作用域 局部作用域 global和nonlocal 函数对象 在Python中,一切皆对象,函数也是 ...