周末打了个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. GitHub 搭建博客,出现 hexo g -d 报错

    想搭建一个个人博客,但是在将博客推送到Github上的时候在git bash 下运行hexo g -d命令出现错误: 错误如下:  fatal: HttpRequestException encoun ...

  2. Archlinux笔记本安装手记

    最近看着Linux Mint里一揽子乱七八糟的应用和散布各处的配置文件愈发烦躁,便想体验下大名鼎鼎的Arch,网上的帖子们把Arch Linux的安装难度描述的非常可怕,但实际上跟着Wiki一步一步来 ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - D

    题目链接:http://codeforces.com/contest/831/problem/D 题意:在一个一维坐标里,有n个人,k把钥匙(钥匙出现的位置不会重复并且对应位置只有一把钥匙),和一个终 ...

  4. zabbix 4.2 发送警告邮件Python脚本

    #!/usr/bin/env python#-*- coding: UTF-8 -*-import os,sysimport getoptimport smtplibfrom email.MIMETe ...

  5. FM

    1.FM (因子分解机) 2.FM的作用: (1)特征组合是许多机器学习建模过程中遇到的问题,如果对特征直接进行建模,很可能会忽略掉特征与特征之间的关联信息,因此,可以通过构建新的交叉特征这一特征组合 ...

  6. JAVA泛型通配符T,E,K,V区别,T以及Class<T>,Class<?>的区别

    1. 先解释下泛型概念 泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛 ...

  7. bui拍照上传、相册上传注意事项

    1.控制台输入 bui.currentPlatform  可查看工程项目基于什么平台  如:bingotouch 2.如果是 bingotouch , 在 index.js 或者其它配置的地方, 加上 ...

  8. Task3.PyTorch实现Logistic regression

    1.PyTorch基础实现代码 import torch from torch.autograd import Variable torch.manual_seed(2) x_data = Varia ...

  9. Integrating .NET Code and SQL Server Reporting Services

    SQL Server Reporting Services versions 2000 and 2005 (SSRS) has many powerful features. SSRS has a w ...

  10. windows下使用Ant编译Android项目

    1. 安装ant,配置环境变量 2. 执行命令: android update project -p 项目路径 例:android update project -p D:\project\UI_de ...