周末打了个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校赛的更多相关文章

  1. 浙江理工2015.12校赛-A

    孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...

  2. 2015 多校赛 第五场 1010 (hdu 5352)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...

  3. 2015 多校赛 第一场 1007 (hdu 5294)

    总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...

  4. GDUT校赛

    题目链接:http://4.gdutcode.sinaapp.com/contest.php?cid=1021 F 题意:给出n和m,要求满足gcd(x,y)=n && lcm(x,y ...

  5. 浙江理工2015.12校赛-F Landlocked

    Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...

  6. 浙江理工2015.12校赛-G Jug Hard

    Jug Hard Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1172 Solved: 180 Description You have two e ...

  7. 浙江理工2015.12校赛-B 七龙珠

    七龙珠 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 781 Solved: 329 Description 话说孙壕请吃了青岛大虾后,一下子变穷了,就 ...

  8. GDUT 校赛02 dp回文串

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABSkAAAIhCAIAAAAtmainAAAgAElEQVR4nOzdfaxkd33n+ZJacstqa3 ...

  9. GDUT 校赛01 dp

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABT8AAAILCAIAAAChHn9YAAAgAElEQVR4nOy9f4il13nneUGgxrRYux ...

随机推荐

  1. 浅谈协议(二)——视频流协议 [RTP/RTCP/RTMP/HTTP_FLV]

  2. linux设定 runlevel 3

    runlevel 查看当前系统运行级别 vi /etc/inittab //运行级别配置文件

  3. Firewalld--02 端口访问/转发、服务访问、源地址管理

    目录 防火墙端口访问/转发.服务访问.源地址管理 1. 防火墙端口访问策略 2. 防火墙服务访问策略 3.防火墙接口管理 4.防火墙源地址管理 5. 防火墙端口转发策略 防火墙端口访问/转发.服务访问 ...

  4. lsattr 查看文件扩展属性

    1. 命令功能 lsattr查看 是否有chattr设置的权限. 2. 使用范例 [root@localhost data]# lsattr resolv.conf -----a-------e- r ...

  5. K8S进入容器方法

    前言 k8s如何进入一个pod里有多个容器的方法 参考地址 https://blog.csdn.net/aa1215018028/article/details/81205691 方法1 kubect ...

  6. Photoshop画笔工具的使用

    现在我们按下[B]从工具栏选择画笔工具,如果选中了铅笔就[SHIFT B]切换到画笔.然后按下[D],它的作用是将颜色设置为默认的前景黑色.背景白色.也可以点击工具栏颜色区的默认按钮(下左图红色箭头处 ...

  7. Linux下python pip手动安装笔记

    今天查问题, 从redis集群中模糊查询某个key, 用一些重复的命令, 链接不同的node, redis-cli 去查, 感觉不舒服. 考虑写一些shell或py来简化一下. 一查环境, 安装了py ...

  8. [POJ1934] Trip

    问题描述 Alice and Bob want to go on holiday. Each of them has planned a route, which is a list of citie ...

  9. Java缓冲字符读取

    public class BufferedReaderDemo { public static void main(String[] args) throws IOException { // 创建流 ...

  10. 028:with标签使用详解

    with标签使用详解: 1.在模板中享用使用变量,可以通过  with  语句实现: 2.with  有两种用法,具体情况如下 ( 包括注意事项 ) : index.html: <p>wi ...