2014 UESTC 暑前集训队内赛(2) 部分解题报告
B.Cuckoo for Hashing
模拟题。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define N 50007 int a[],b[]; int main()
{
int n1,n2,m,i;
int x,fx,tx;
int tmp,tmp2;
int cs = ;
while(scanf("%d%d%d",&n1,&n2,&m)!=EOF && (n1||n2||m))
{
memset(a,-,sizeof(a));
memset(b,-,sizeof(b));
while(m--)
{
scanf("%d",&x);
fx = x%n1;
tx = ;
if(a[fx] == -)
{
a[fx] = x;
continue;
}
tmp2 = x;
while(a[fx] != -)
{
tmp = a[fx];
a[fx] = tmp2;
tx = tmp%n2;
if(b[tx] != -)
{
tmp2 = b[tx];
b[tx] = tmp;
fx = tmp2%n1;
}
else
{
b[tx] = tmp;
break;
}
}
if(a[fx] == -)
a[fx] = tmp2;
}
printf("Case %d:\n",cs++);
int flag = ;
//printf("Table 1\n");
for(i=;i<n1;i++)
{
if(a[i] != -)
{
flag = ;
break;
}
}
if(flag)
{
printf("Table 1\n");
for(i=;i<n1;i++)
{
if(a[i] != -)
printf("%d:%d\n",i,a[i]);
}
}
flag = ;
for(i=;i<n2;i++)
{
if(b[i] != -)
{
flag = ;
break;
}
}
if(flag)
{
printf("Table 2\n");
for(i=;i<n2;i++)
{
if(b[i] != -)
printf("%d:%d\n",i,b[i]);
}
}
}
return ;
}
C.Playing Fair with Cryptography
模拟题,注意细节就好。遇到J的情况要及时跳走。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define N 50007 char mp[][];
char key[],text[];
int vis[]; string RUN(string ss)
{
int i,j;
int a,b;
int c,d;
string ans = "";
for(i=;i<;i++)
{
for(j=;j<;j++)
{
if(mp[i][j] == ss[])
a = i,b = j;
if(mp[i][j] == ss[])
c = i,d = j;
}
}
if(a == c)
{
int newb = (b+)%;
ans += mp[a][newb];
int newd = (d+)%;
ans += mp[a][newd];
return ans;
}
else if(b == d)
{
int newa = (a+)%;
ans += mp[newa][b];
int newc = (c+)%;
ans += mp[newc][b];
return ans;
}
else
{
int newb = d;
int newd = b;
ans += mp[a][newb];
ans += mp[c][newd];
return ans;
}
} int main()
{
int t,i,cs = ,j,k;
int x,y;
scanf("%d",&t);
getchar();
while(t--)
{
gets(key);
gets(text);
int len1 = strlen(text);
int len2 = strlen(key);
memset(vis,,sizeof(vis));
k = ;
for(i=;i<len2;i++)
{
char ch = key[i];
if((ch >= 'A' && ch <= 'Z'))
{
if(vis[ch-'A'])
continue;
vis[ch-'A'] = ;
mp[k/][k%] = ch;
k++;
}
else if(ch >= 'a' && ch <= 'z')
{
ch -= ;
if(vis[ch-'A'])
continue;
vis[ch-'A'] = ;
mp[k/][k%] = ch;
k++;
}
}
for(char chh = 'A';chh<='Z';chh++)
{
if(chh == 'J')
continue;
if(!vis[chh-'A'])
{
mp[k/][k%] = chh;
k++;
}
}
//alpha table established
char ss[];
k = ;
for(i=;i<len1;i++)
{
if(text[i] >= 'A' && text[i] <='Z')
ss[k++] = text[i];
else if(text[i] >= 'a' && text[i] <= 'z')
ss[k++] = text[i]-;
}
ss[k] = '\0';
printf("Case %d: ",cs++);
int nowch = ;
char nowchar;
string cy = "";
for(i=;i<k-;i+=)
{
if(nowch == )
nowch++,nowch%=;
if(ss[i] == ss[i+])
{
if(ss[i] == (nowch%) + 'A')
{
nowchar = (++nowch)% + 'A';
if(nowchar == 'J')
nowch++,nowchar = 'K';
}
nowchar = (nowch%) + 'A';
if(nowchar == 'J')
nowch++,nowchar = 'K';
cy = "";
cy += ss[i];
cy += nowchar;
cout<<RUN(cy);
nowch = (nowch+)%;
i -= ;
}
else
{
cy = "";
cy += ss[i];
cy += ss[i+];
cout<<RUN(cy);
}
}
if(i == k-)
{
nowchar = nowch% + 'A';
if(ss[i] == nowchar)
{
nowchar = (++nowch)% + 'A';
}
if(nowchar == 'J')
nowch++,nowchar = 'K';
cy = "";
cy += ss[i];
cy += nowchar;
cout<<RUN(cy);
}
cout<<endl;
}
return ;
}
H.The Urge to Merge
DP。借鉴标程代码。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#define Mod 1000000007
using namespace std;
#define N 50007 int mp[][];
ll dp[][]; ll Max(ll a,ll b,ll c,ll d)
{
return max(max(max(a,b),c),d);
} int main()
{
int cs = ,n;
int i,j,k;
while(scanf("%d",&n)!=EOF && n)
{
for(i=;i<;i++)
for(j=;j<=n;j++)
scanf("%d",&mp[i][j]);
//memset(dp,0,sizeof(dp));
for(i=;i<;i++)
dp[i][] = dp[i][] = ;
dp[][] = mp[][]*mp[][];
dp[][] = mp[][]*mp[][];
ll k1 = Max(dp[][],dp[][],,);
ll k2 = ;
ll s1,s2,s3,s4,s5; for(j=;j<=n;j++)
{
s1 = mp[][j-]*mp[][j];
s2 = mp[][j-]*mp[][j];
s3 = mp[][j-]*mp[][j];
s4 = mp[][j]*mp[][j];
s5 = mp[][j]*mp[][j]; dp[][j] = Max(k2,dp[][j-],dp[][j-],dp[][j-])+s1; //第一种组合
dp[][j] = Max(k2,dp[][j-],dp[][j-],dp[][j-])+s2; //第二种组合
dp[][j] = Max(k2,dp[][j-],dp[][j-],dp[][j-])+s3; //第三种组合 dp[][j] = Max(k2+s1+s2,dp[][j-]+s1+s2,k1+s4,);
dp[][j] = Max(k2,dp[][j-],,)+s1+s3;
dp[][j] = Max(k2+s2+s3,dp[][j-]+s2+s3,k1+s5,);
dp[][j] = Max(k2+s1+s2+s3,dp[][j]+s5,dp[][j]+s4,);
k2 = k1;
for(i=;i<;i++)
k1 = max(k1,dp[i][j]);
}
ll ans = -Mod;
for(i=;i<;i++)
ans = max(ans,dp[i][n]);
printf("Case %d: %d\n",cs++,ans);
}
return ;
}
(没做出来的以后持续更新)
2014 UESTC 暑前集训队内赛(2) 部分解题报告的更多相关文章
- 2014 UESTC 暑前集训队内赛(3) 部分解题报告
B.Battle for Silver 定理:完全图Kn是平面图当且仅当顶点数n<=4. 枚举所有完全图K1,K2,K3,K4,找出最大总权重. 代码: #include <iostrea ...
- 2014 UESTC 暑前集训队内赛(1) 解题报告
A.Planting Trees 排序+模拟 常识问题,将耗时排一个序,时间长的先种,每次判断更新最后一天的时间. 代码: #include <iostream> #include < ...
- 2014 UESTC暑前集训数据结构专题解题报告
A.Islands 这种联通块的问题一看就知道是并查集的思想. 做法:从高水位到低水位依序进行操作,这样每次都有新的块浮出水面,可以在前面的基础上进行合并集合的操作.给每个位置分配一个数字,方便合并集 ...
- 2014 UESTC暑前集训搜索专题解题报告
A.解救小Q BFS.每次到达一个状态时看是否是在传送阵的一点上,是则传送到另一点即可. 代码: #include <iostream> #include <cstdio> # ...
- 2014 UESTC暑前集训动态规划专题解题报告
A.爱管闲事 http://www.cnblogs.com/whatbeg/p/3762733.html B.轻音乐同好会 C.温泉旅馆 http://www.cnblogs.com/whatbeg/ ...
- 2014 UESTC暑前集训图论专题解题报告
A.方老师和缘分 http://www.cnblogs.com/whatbeg/p/3765621.html B.方老师和农场 http://www.cnblogs.com/whatbeg/p/376 ...
- 模拟赛T2 交换 解题报告
模拟赛T2 交换 解题报告 题目大意: 给定一个序列和若干个区间,每次从区间中选择两个数修改使字典序最小. \(n,m\) 同阶 \(10^6\) 2.1 算法 1 按照题意模拟,枚举交换位置并比较. ...
- nowcoder(牛客网)提高组模拟赛第一场 解题报告
T1 中位数(二分) 这个题是一个二分(听说是上周atcoder beginner contest的D题???) 我们可以开一个数组b存a,sort然后二分b进行check(从后往前直接遍历check ...
- UESTC-第五届ACM趣味程序设计竞赛第四场(正式赛)--不完全解题报告
比赛链接: http://acm.uestc.edu.cn/contest.php?cid=230 A.Police And The Thief ---UESTC 1913 简单博弈,先假设在警察先走 ...
随机推荐
- EffectiveJava——用函数对象表示策略
有些语言支持函数指针.代理.lambda表达式,或者支持类似的机制,允许程序把“调用特殊函数的能力”储存起来并传递这种能力.这种机制通常用于允许函数的调用者通过传入第二个函数,来指定自己的行为.比较器 ...
- 【GOF23设计模式】适配器模式
来源:http://www.bjsxt.com/ 一.[GOF23设计模式]_适配器模式.对象适配器.类适配器.开发中场景 适配器模式 笔记本电脑只有USB接口,新买的键盘是PS2接口的,需要用适 ...
- ASP.NET本质论第一章网站应用程序学习笔记1
1.统一资源标示符 1) 格式:协议://主机[.端口号][绝对路径[?参数]],在Http://www.kencery.com/hyl/index/login中,http表示协议的名称,www.ke ...
- CSS基础选择器温故-1
1.基本选择器语法 2.浏览器兼容性:浏览器对基本选择器都是一路绿灯通行,可以放心使用. 3.通配选择器:选择所有元素,也可以选择某个元素下的所有元素 (1)选择所有元素: *{margin: 0;p ...
- English Training Material - 03
Cross-cultural understanding (2) 1 The following text is about cultural diversity. Read it through o ...
- 如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点
问题现象 Visual Studio在开发SharePoint的时候,发布部署包后,首次打开及调试站点页面的时候会非常的慢 解决方案 使用PowerShell脚本,加载SharePoint插件后遍历所 ...
- Python基础(9)--正则表达式
正则表达式是一个很有用的工具,可处理复杂的字符匹配和替换工作.在Python中内置了一个re模块以支持正则表达式. 正则表达式有两种基本的操作,分别是匹配和替换. 匹配就是在一个文本字符串中搜索匹配一 ...
- Spring(九)Spring对事务的支持
一.对事务的支持 事务:是一组原子操作的工作单元,要么全部成功,要么全部失败 Spring管理事务方式: JDBC编程事务管理:--可以控制到代码中的行 可以清楚的控制事务的边界,事务控制粒度化细(编 ...
- 我对XCode Objective-c Cocoa的简单理解
我对XCode Objective-c Cocoa的简单理解 Xcode Xcode说的通俗一点就是开发OS X 和 iOS 应用程序的. 如果我们想要认真点说 ,Xcode 是运行在操作系统Mac ...
- 自定义Dialog以及Dialog返回值到Activity
步骤: 1.定义自定义的Dialog的布局文件 2.写一个类MyDialog继承Dialog 3.Dialog 返回值到Activity的方法是定义一个接口,接口中定义返回值到Activity的方法, ...