2016 ACM-ICPC EC-Final
UVALive7897 Number Theory Problem (找规律签到)
思路:
8的幂次都是可以的,因为an-1一定能分解成a-1乘上一个多项式。
看不出来也没关系,打表就发现每三个数有一个7的倍数。
代码:
#include <cstdio> using namespace std; int main()
{
int T, kase = ;
scanf("%d", &T);
while (T--) {
int N;
scanf("%d", &N);
printf("Case #%d: %d\n", kase++, N/);
} return ;
}
UVALive7899 Mr. Panda and Strips (暴搜+尺取+剪枝)
思路:
我也不知道这是什么做法,神棍剪枝吧-。=
尺取大法好(超大声)
#include <bits/stdc++.h> using namespace std;
const int MAX_N = 1e3 + ;
const int MAX_C = 1e5 + ; int N;
int C[MAX_N], len[MAX_N];
int ans;
bool vis[MAX_C]; inline void reset() {
for (int i = ; i <= N; i++) vis[C[i]] = false;
} void init()
{
cin >> N;
for (int i = ; i <= N; i++)
scanf("%d", C+i);
C[N+] = ;
reset();
} inline int jump(int pos, int limit) {
int l = pos, r = pos, res = -;
while (r <= N) {
while (!vis[C[r]] && r <= N) vis[C[r++]] = true;
if (len[l] < limit) break;
res = max(res, r-l);
while ( vis[C[r]] && l <= r) vis[C[l++]] = false;
}
for (int i = l; i < r; i++) vis[C[i]] = false;
return res;
} int main()
{
int T, kase = ;
cin >> T;
while (T--) {
init();
for (int i = ; i <= N; i++, reset()) {
len[i] = ;
for (int j = i; j <= N && !vis[C[j]]; j++)
len[i]++, vis[C[j]] = true;
}
len[N+] = ;
for (int i = N; i >= ; i--)
len[i] = max(len[i], len[i+]);
ans = len[]; for (int i = ; i <= N; i++, reset())
for (int j = i; j <= N && !vis[C[j]]; j++) {
vis[C[j]] = true;
if (ans >= j-i+ + len[j]) continue;
int res = jump(j+, ans-(j-i+));
ans = max(ans, j-i+ + res);
}
reset();
printf("Case #%d: %d\n", kase++, ans);
}
return ;
}
/*
3
8
3 1 2 1 6 1 2 5
3
1 2 3
3
1 1 1
*/
UVALive7900 Ice Cream Tower (二分+贪心)
假思路:
贪心地取冰淇淋球,尽可能地早点做出Tower,不能放在之前的冰淇淋上的球当作新的底座。
#include <bits/stdc++.h> using namespace std;
typedef long long ll;
const int MAX_N = 3e5 + ; struct QNode{
ll val;
int len;
QNode(ll v = , int l = ) : val(v), len(l) {}
}; ll B[MAX_N];
queue <QNode> Q; int main()
{
int T, kase = ;
cin >> T;
while (T--) {
int N, K, ans = ;
cin >> N >> K;
for (int i = ; i <= N; i++)
scanf("%lld", B+i);
sort(B+, B++N);
for (int i = N; i >= ; i--) {
if (Q.empty()) {
Q.push(QNode(B[i], ));
continue;
}
QNode cur = Q.front();
if (cur.val/ >= B[i]) {
Q.pop();
if (cur.len+ == K)
ans++;
else
Q.push(QNode(B[i], cur.len+));
}
else {
Q.push(QNode(B[i], ));
}
}
while (!Q.empty())
Q.pop();
printf("Case #%d: %d\n", kase++, ans);
}
return ;
}
/*
3
4 2
1 2 3 4
6 3
1 1 2 2 4 4
6 3
1 1 2 2 3 4
*/
自我hack【精通】。。codeforces gym上的数据比较强,上面的代码就不能过了。
思路:
二分答案,用上面的贪心法验证。。。。O(Nlog(N/K))
#include <bits/stdc++.h> using namespace std;
typedef long long ll;
const int MAX_N = 3e5 + ;
struct Node{
ll val, len;
Node(ll v = , ll l = ) : val(v), len(l) {}
}; int N, K;
ll B[MAX_N]; queue <Node> Q;
bool solve(int ans){
while (!Q.empty())
Q.pop();
if (K == )
return true;
for (int i = ; i <= ans; i++)
Q.push(Node(B[i], ));
for (int i = ans+; i <= N; i++) {
if (Q.empty())
break;
Node cur = Q.front();
if (B[i]/ >= cur.val) {
Q.pop();
if (cur.len == K-)
continue;
Q.push(Node(B[i], cur.len+));
}
}
return Q.empty();
} int main()
{
int T;
cin >> T;
for (int kase = ; kase <= T; kase++) {
cin >> N >> K;
for (int i = ; i <= N; i++)
scanf("%lld", B+i);
sort(B+, B++N);
int ansl = , ansr = N, ans = ;
while (ansl <= ansr) {
int mid = (ansl + ansr) >> ;
if (solve(mid)) {
ans = max(ans, mid);
ansl = mid+;
}
else {
ansr = mid-;
}
}
printf("Case #%d: %d\n", kase, ans);
}
return ;
}
/*
3
4 2
1 2 3 4
6 3
1 1 2 2 4 4
6 3
1 1 2 2 3 4
*/
UVALive7901 Bet (数学+贪心+高精度除法(long double))
思路:
小学数学题-。=
贪心地选性价比高的队伍,能选多个队伍的条件是这些队伍的A/(A+B)的和小于1。。。。这个精度啊。。比赛的时候WA来WA去就是没想到,Dilthey瞄了一眼题解发现是高精度除法,long double够用。。。换上long double就AC了。。在现场的话,不知道这个高精度估计要悔恨终身了。
#include <bits/stdc++.h> using namespace std;
const int MAX_N = + ;
const long double money = 1e3 + ;
const long double eps = 1e-; long double A[MAX_N], B[MAX_N], C[MAX_N]; int main()
{
int T;
cin >> T;
for (int kase = ; kase <= T; kase++) {
int N;
cin >> N;
for (int i = ; i <= N; i++) {
char x;
cin >> A[i] >> x >> B[i];
C[i] = (long double)A[i] / (A[i] + B[i]);
}
sort(C+, C++N);
int cnt = ;
long double sum = ;
while (cnt+ <= N && sum + C[cnt+]*money < money-eps) {
sum += C[++cnt]*money;
}
printf("Case #%d: %d\n", kase, cnt);
}
return ;
}
/*
3
2
5:3
2:7
2
1:1
1:1.01
3
1:1.1
1:0.2
1.5:1.7
*/
/*
10
12
1:10
1:10
1:10
1:10
1:10
1:10
1:10
1:10
1:10
1:10
1:10
1:10
12
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
1:9.9
12
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
1:10.1
*/
UVALive7908 Great Cells (数学思维+快速幂)
思路:Dilthey的博客
#include <bits/stdc++.h> using namespace std;
typedef long long ll;
const ll MOD = ; ll fpow(ll a, ll p) {
ll ans = ;
while (p) {
if (p&) ans *= a, ans %= MOD;
a *= a, a %= MOD;
p >>= ;
}
return ans;
} int main()
{
int T;
cin >> T;
for (int kase = ; kase <= T; kase++) {
ll N, M, K;
cin >> N >> M >> K;
ll ans = ;
for (ll i = ; i <= K; i++)
ans += fpow(i-, N-+M-), ans %= MOD;
ans *= N*M, ans %= MOD;
ans *= fpow(K, (N-)*(M-)), ans %= MOD;
ans += fpow(K, N*M), ans %= MOD;
printf("Case #%d: ", kase);
cout << ans << endl;
}
return ;
}
/*
3
2 2 2
2 3 2
3 4 5
*/
UVALive7908 World Cup (3进制状压+枚举)
思路:
把所有的可能答案都预处理出来,有36个,直接枚举时间复杂度为O(4*36T)。
预处理的时候把比赛结果的可能性:胜负,平局,负胜压成六位三进制数即可。
#include <bits/stdc++.h> using namespace std;
const int l[] = {, , , , , };
const int r[] = {, , , , , };
const int len = ; int pow(int a, int p)
{
int ans = ;
while (p) {
if (p&) ans *= a;
a *= a;
p >>= ;
}
return ans;
} int A[];
int res[len+][]; void init()
{
memset(res, , sizeof res);
for (int i = ; i < len; i++) {
int tmp = i;// mod 3 = 0胜,1平,2败。
for (int j = ; j < ; j++) {
if (tmp % == ) {
res[i][l[j]] += ;
}
else if (tmp % == ) {
res[i][l[j]]++;
res[i][r[j]]++;
}
else if (tmp % == ) {
res[i][r[j]] += ;
}
tmp /= ;
}
}
} int main()
{
init();
int T;
cin >> T;
for (int kase = ; kase <= T; kase++) {
for (int i = ; i <= ; i++)
scanf("%d", A+i);
int valid = ;
for (int i = ; i < len; i++) {
int j;
for (j = ; j <= ; j++)
if (A[j] != res[i][j])
break;
if (j == ) {
valid++;
}
}
printf("Case #%d: ", kase);
if (!valid)
puts("Wrong Scoreboard");
else {
sort(A, A+);
if (valid > )
puts("No");
else
puts("Yes");
}
}
return ;
}
/*
3
9 6 3 0
6 6 6 0
10 6 3 0
*/
2016 ACM-ICPC EC-Final的更多相关文章
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元
hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
Friends and Enemies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
随机推荐
- vue中nextTick和$nextTick的差别
<ul id="demo"> <li v-for="item in list">{{item}}</div> < ...
- window.open打开新窗口 参数
1,基本描述 oNewWindow = window.open( sURL , sName , sFeatures, bReplace) window.open在打开一个窗口(其url为sURL)后, ...
- MySql查询最近一个月,一周,一天
最近一个月 SELECT * FROM table WHERE DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(time); 本月.当前月 SELEC ...
- Mysql计算并保留两位小数
如:123456.789 转成 123456.79 自动,));
- asp.net webapi 返回json结果的方法
第一种: public static void Register(HttpConfiguration config) { //1.将默认的xml格式化程序清除 GlobalConfiguration. ...
- 初识数据库、初识MySQL
一.为什么要用数据库 # 1.将文件和程序存在一台机器上是很不合理的. # 2.操作文件是一件很麻烦的事. 所以就出现了一个新的概念 —— 数据库 你可以理解为 数据库 是一个可以在一台机器上独立工作 ...
- div 自适应高度
自适应高度 ,设置最小高度:通常情况下,没有设置高度,div默认自适应高度且无最低高度 1 div{ _height:200px; /* css 注解: 仅IE6设别此属性,假定最低高度是200px ...
- ubuntu 搭建ss和使用方法
一 ubuntu 搭建ssa.安装 sudo apt-get install python-gevent python-pip python-m2crypto sudo pip insta ...
- 关于对Access数据库的学习报告
学习Access数据库的报告 一.前言 一开始我对access一窍不通,甚至不知道它是干什么的,后来经过网上资料的查阅对它略有了解.microsoft office access是由微软发布的关联式数 ...
- oracle 正则表达式 匹配
oracle 正则表达式 在实际应用中,想排除带有中文的字段值: select h.froomnumber from t_broker_house h where REGEXP_LIKE(froomn ...