2015 GDUT校赛
周末打了个GDUT的校赛,也是作为SCAU的一场个人排位。
比赛中竟然卡了个特判,1个半钟就切了5条了,然后一直卡。
还有其他两条可以做的题也没法做了,性格太执着对ACM来说也是错呀。
讲回正题 。
A 游戏王 .
目的是集齐6张卡, 然后n个小伙伴手上持有卡num, 给出m种集合 , Stubird需要有某个集合中的卡片才能用c的花费去买这张卡片。
做法是状压dp , 开一个 dp[st] , 表示st( 0 <= st < (1<<6) ) 这个集合最小花费 。
然后开一个邻接链表 g[st] 这样, 存着st这个状态可以去到那些状态 , 费用是多少 。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std ; typedef long long LL ;
typedef pair<int,int> pii;
#define X first
#define Y second
const int inf = 1e9+;
const int N = << ; vector<pii>g[N];
LL dp[N] ; int main () {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int _ ; scanf("%d",&_);
while( _-- ) { for( int i = ; i < N ; ++i ) g[i].clear() , dp[i] = inf ;
int n ; scanf("%d",&n);
for( int i = ; i < n ; ++i ) {
int m , num ;
scanf("%d%d",&m,&num);
for( int j = ; j < m ; ++j ) {
int k ; scanf("%d",&k);
int st = , vst , c ;
while( k-- ) {
scanf("%d",&vst);
st |= (<<vst) ;
}
scanf("%d",&c);
for( int y = ; y < N ; ++y ) {
bool tag = true ;
for( int z = ; z < ; ++z ) {
if( (st&(<<z)) && (!(y&(<<z))) ) {
tag = false ; break ;
}
}
if( tag ) g[y].push_back(pii(num,c));
}
}
}
dp[] = ;
for( int st = ; st < N ; ++st ) {
for( int i = ; i < g[st].size() ; ++i ) {
int vst = st | (<<g[st][i].X) , w = g[st][i].Y ;
dp[vst] = min( dp[vst] , dp[st] + w ) ;
}
}
if( dp[N-] == inf ) puts("-1");
else printf("%d\n",dp[N-]);
}
} /**************************************************************
Problem: 1116
User: hl_mark
Language: C++
Result: Accepted
Time:220 ms
Memory:2324 kb
****************************************************************/
B.完美串
给出一个01串,要该串取反再翻转后与原串相同,至少要多加多少个 0 or 1 。
输入串a后 , 构造一个串b ( a取反再翻转 ) 求它们的最长公共子序列,这里是个dp ..
答案就是 n - dp[n][n] , 首先要证明 n - dp[n][n] 这个答案是无误的 。
要符合条件串长要偶数, 前半段跟后半段的以中线反对称的 。
设 最长公共子序列长度为 x , 补充 n - x 个 0 , 1 之后必然会符合题目要求,因为添加的时候符合反对称的性质。
那为何是 这个答案是最优? 反证吧。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std ;
const int N = ;
int dp[N][N] , a[N] , b[N] ;
char s[N];
int main () {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int _ ; scanf("%d",&_);
while( _-- ) {
int n ;
scanf("%d",&n);
memset( dp , , sizeof dp );
scanf("%s",s);
for( int i = ; i < n ; ++i ) {
a[i+] = s[i] - '' ;
}
for( int i = n ; i > ; --i ) {
b[i] = a[n-i+] ;
b[i] ^= ;
}
// for( int i = 1 ; i <= n ; ++i ) cout << a[i] ; cout <<endl ;
// for( int i = 1 ; i <= n ; ++i ) cout << b[i] ; cout <<endl ;
for( int i = ; i <= n ; ++i ) {
for( int j = ; j <= n ; ++j ) {
if( a[i] == b[j] ) dp[i][j] = dp[i-][j-] + ;
else {
dp[i][j] = max( dp[i][j-] , dp[i-][j] ) ;
}
}
}
int ans = n ;
for( int i = ; i <= n ; ++i ) {
for( int j = ; j <= n ; ++j ) {
ans = min( ans , n - dp[i][j] );
}
}
printf("%d\n",ans);
}
} /**************************************************************
Problem: 1109
User: hl_mark
Language: C++
Result: Accepted
Time:384 ms
Memory:5476 kb
****************************************************************/
C . GCD = n , LCM = m 的对数
其实就是对 n , m 分解之后。 对其不同次幂质因子的分配方案数 。 比赛过程中加了一个错的特判。 搞得一直wa~
#include <cstdio>
#include <iostream>
using namespace std ;
const int N = ;
long long fac[N] , cnt[N] , tot ;
void solve( long long x ) {
for( long long i = ; i * i <= x ; ++i ) if( x % i == ){
fac[tot] = i ; cnt[tot] = ;
while( x % i == ) { x /= i ; cnt[tot]++ ; }
tot++ ;
}
if( x != ) { fac[tot] = x ; cnt[tot] = ; tot++ ; }
}
int main () {
int _ ; scanf("%d",&_);
while( _-- ) {
long long n , m ;
tot = ;
scanf("%lld%lld",&n,&m);
if( m % n ) { puts(""); continue ; }
solve(n); int c = ;
for( int i = ; i < tot ; ++i ) if( m % fac[i] == ) {
int cc = ;
while( m % fac[i] == ) { m /= fac[i] ; cc++ ;}
if( cc != cnt[i] ) c++ ;
}
tot = ; solve( m ) ; c += tot ;
long long ans = ;
for( int i = ; i < c - ; ++i ) ans = ans * ;
printf("%lld\n",ans);
}
}
D . 煮菜 , 一分钟可以同时煮 m 个菜 。
ti 为每个菜需要的时间, 若 sum = sigma(ti) , 总时间 T = sum/m + ( sum % m ==0 ? 0 : 1 ) 。
若 T > Max ( ti ) .. 是必然能够很配出方案使得时间为T 的 , 否则结果就是 Max(ti) .
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std ;
typedef pair<int,int> pii;
#define X first
#define Y second
const int N = ;
int main () {
int _ ; scanf("%d",&_);
while( _-- ) {
int sum = , n , m , mx = - , x ;
scanf("%d%d",&n,&m);
for( int i = ; i < n ; ++i ) {
scanf("%d",&x);
mx = max( mx , x );
sum += x ;
}
int t = ( sum / m ) + ( sum % m == ? : ) ;
int ans = max( mx , t );
printf("%d\n",ans);
}
}
E. 强迫症关灯
因为 n , m 只有100,直接暴力, 如果 n , m 达到1e6 的话就线段树吧
#include <cstdio>
#include <cstring>
using namespace std ;
int b[];
int main () {
int _ ; scanf("%d",&_);
while( _-- ) {
memset( b , , sizeof b );
int n , m ; scanf("%d%d",&n,&m);
while( m-- ) {
int x ; scanf("%d",&x);
for( int i = x ; i <= n ; ++i ) {
if( !b[i] ) b[i] = x ;
else break ;
}
}
printf("%d",b[]);
for( int i = ; i <= n ; ++i ) {
printf(" %d",b[i]);
}puts("");
}
}
F.找规律
题目都说了找规律,然后就暴力一下前100个看看规律,然后就可以看出来了
#include <cstdio>
using namespace std ;
int main () {
int n ;
while( ~scanf("%d",&n) ) {
printf("%d\n",( n / * + ( n % > ? : ) ) );
}
} /**************************************************************
Problem: 1122
User: hl_mark
Language: C++
Result: Accepted
Time:32 ms
Memory:964 kb
****************************************************************/
G. 用多少条边可以把玩具连起来, 就是求连通分量个数,再-1
写并查集就可以实现了
#include <cstdio>
#include <iostream>
using namespace std ;
const int N = ;
int fa[N] ;
bool vis[N] ;
inline int find( int k ) { return fa[k] = ( fa[k] == k ? k : find(fa[k])); }
int main () {
int _ ; scanf("%d",&_);
while( _-- ) {
int n , m ; scanf("%d%d",&n,&m);
for( int i = ; i <= n ; ++i ) fa[i] = i , vis[i] = false ;
while( m-- ) {
int x , y ; scanf("%d%d",&x,&y);
int fx = find(x) , fy = find(y);
fa[fy] = fx ;
}
int cnt = ;
for( int i = ; i <= n ; ++i ) {
int fx = find(i);
if( !vis[fx] ) { vis[fx] = true ; cnt++; }
}
printf("%d\n",cnt-);
}
} /**************************************************************
Problem: 1118
User: hl_mark
Language: C++
Result: Accepted
Time:132 ms
Memory:1972 kb
****************************************************************/
F. 移动2只手指,点音符 。。
简单dp .. dp[i][j][k] 表示点到第i 个音符 , 第一只手指在 j , 第2只手指在 k 的最小花费
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std ;
typedef pair<int,int> pii;
#define X first
#define Y second
const int N = ;
int dp[N][][] , x[N] ;
int main () {
int _ ; scanf("%d",&_);
while( _-- ) {
int n ; scanf("%d",&n);
for( int i = ; i <= n ; ++i ) scanf("%d",&x[i]);
memset( dp , 0x3f , sizeof dp );
int inf = dp[][][] ;
dp[][][] = ;
for( int i = ; i < n ; ++i ) {
for( int j = ; j < ; ++j ) {
for( int k = ; k < ; ++k ) {
if( dp[i][j][k] >= inf ) continue ;
dp[i+][j][ x[i+] ] = min( dp[i+][j][ x[i+] ] , dp[i][j][k] + abs( x[i+] - k ) );
dp[i+][ x[i+] ][k] = min( dp[i+][ x[i+] ][k] , dp[i][j][k] + abs( x[i+] - j ) );
}
}
}
int ans = inf ;
for( int i = ; i < ; ++i )
for( int j = ; j < ; ++j )
ans = min( ans , dp[n][i][j] );
printf("%d\n",ans);
}
} /**************************************************************
Problem: 1115
User: hl_mark
Language: C++
Result: Accepted
Time:92 ms
Memory:2932 kb
****************************************************************/
2015 GDUT校赛的更多相关文章
- 浙江理工2015.12校赛-A
孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...
- 2015 多校赛 第五场 1010 (hdu 5352)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- GDUT校赛
题目链接:http://4.gdutcode.sinaapp.com/contest.php?cid=1021 F 题意:给出n和m,要求满足gcd(x,y)=n && lcm(x,y ...
- 浙江理工2015.12校赛-F Landlocked
Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...
- 浙江理工2015.12校赛-G Jug Hard
Jug Hard Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1172 Solved: 180 Description You have two e ...
- 浙江理工2015.12校赛-B 七龙珠
七龙珠 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 781 Solved: 329 Description 话说孙壕请吃了青岛大虾后,一下子变穷了,就 ...
- GDUT 校赛02 dp回文串
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABSkAAAIhCAIAAAAtmainAAAgAElEQVR4nOzdfaxkd33n+ZJacstqa3 ...
- GDUT 校赛01 dp
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABT8AAAILCAIAAAChHn9YAAAgAElEQVR4nOy9f4il13nneUGgxrRYux ...
随机推荐
- MySQL的删除语句
虽然现在数据库空间越来越大,但处理数据时候还是有要删除的时候,以下整理了一些最常用的删除语句. 分成两种 一个是删除指定数据,另一个删除所有数据. 一.删除指定数据 DELETE FROM 表名 WH ...
- 02机器学习实战之K近邻算法
第2章 k-近邻算法 KNN 概述 k-近邻(kNN, k-NearestNeighbor)算法是一种基本分类与回归方法,我们这里只讨论分类问题中的 k-近邻算法. 一句话总结:近朱者赤近墨者黑! k ...
- Java8 时间处理类的使用实践(LocalDate...)
有了它,谁还在用Date?Calendar? 其实也不能这么绝对,毕竟还没到那个程度上.Java8 新增了处理时间的一组类(LocalDate.LocalDateTime.LocalTime),刚开始 ...
- html 头部设置
https://juejin.im/post/5a4ae29b6fb9a04504083cac <head> <meta charset="UTF-8"> ...
- Mac xlwings aem.aemsend.EventError: Command failed: The user has declined permission. (-1743)
aem.aemsend.EventError: Command failed: The user has declined permission. (-1743) 关于mac pycharm 使用xl ...
- HTML5 游戏引擎的选择
原生手游市场已是红海,腾讯.网易等寡头独霸天下,H5游戏市场或将成为下一个风口.据笔者所知,很多H5游戏开发团队由于选择引擎不慎导致项目甚至团队夭折.如何选择适合团队和项目的引擎,笔者通过学习和项目实 ...
- Strange fuction hdu 2899
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- vue 3.0 vue-cli项目搭建要点
一.使用vue-cli搭建项目(可使用vue ui图形化界面搭建项目,配置dist时,将名称设为项目名称) 二.项目搭建后 1.配置vue.config.js // 翻阅文档https://cli.v ...
- 学习笔记11 EF查询相当于sql 中的 where in
两种写法 1. int[] Ids={1,2,3} DBContainer db=new DBContainer(); var list=db.表明.where(a=>Ids.Contains( ...
- 23 October
[HAOI2010] 最长公共子序列 求S串与T串的 最长公共子序列 的 长度 及其 个数. 动态规划递推式: \[ f(i,j)=\max\left\{ f(i-1,j), f(i,j-1) \ri ...