周末打了个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. linux 服务器与客户端异常断开连接问题

    服务器与客户端连接,客户端异常断掉之后服务器端口仍然被占用, 到最后是不是服务器端达到最大连接数就没法连接了?领导让我测试这种情况,我用自己的电脑当TCP Client,虚拟机当服务器,连接之后能正常 ...

  2. 测试员小白必经之路----常见的linux操作命令

    linux作为服务器操作系统 linux具有自己的优势,安全.稳定.免费.占有率高 操作系统发展历史 unix>minix>linux linux命令的基本使用 查阅命令帮助信息 comm ...

  3. "不能将值 NULL 插入列 'ID',表 列不允许有 Null 值."

    问题: "不能将值 NULL 插入列 'ID',表 列不允许有 Null 值." 原因: 在进行表创建的时候没有将主键自增字段添加标识. 在使用navicat进行表创建的时候一定要 ...

  4. python面向对象的三大特征--继承

    #什么时候用继承 #1.当类之间有显著不同,并且较小的类是较大的类所需的组件时,用组合比较好 #2.当类之间有很多相同的功能,提供这些共同的功能做成基类,用继承比较好 class Dad: " ...

  5. django:一个RESTfull的接口从wsgi到函数的历程

    1.wsgi将web server参数python化,封装为request对象传递给apllication命名的func对象并接受其传出的response参数,这个application在wsgi.p ...

  6. js关于小数点失精算法修正0.07*100竟然=7.000000000000001

    转发 https://blog.csdn.net/iteye_13003/article/details/82645716

  7. R语言把DataFrame的一行变成向量

    在R语言里面,DataFrame的一列数据本质上可以认为是一个向量或列表,但是一行数据不是. 今天有一个31列的数据集,由于放在第一行的变量名格式不规范,读入数据的时候不能顺带读入变量名.于是跳过首行 ...

  8. [luogu] P3809 【模板】后缀排序 (SA)

    板子,照着题解打的倍增版. #include <iostream> #include <cstdio> #include <cstring> using names ...

  9. SpringCLoud之搭建Zuul网关集群

    1.使用技术 Springboot,SpringCloud,Zuul,Nignx 2.目的 使用Zuul搭建微服务高可用的网关 3.项目创建 3.1 创建注册中心(略) 3.2 创建一个hello-s ...

  10. servlet中中文正常显示,mysql数据库手动插入中文正常显示,servlet向mysql中插入中文显示乱码

    作者:http://5563447.blog.51cto.com/5553447/1422627 问题是:就是POST请求提交表单数据给servlet,通过JDBC插入Mysql,出现中文乱码. 解决 ...