【补】【FZU月赛】【20150515】【待续】
A FZU-2054
水题,比较A,B双方的最大值即可。
B FZU-2055
string,截取‘.’之前和之后然后和给出的文件夹名和拓展名比较就好了啊,不明白为什么那么多人错。
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
string path[maxn], type[maxn];
int main()
{
int T; scanf("%d", &T);
while(T--)
{
int n, m; scanf("%d%d", &n, &m);
string str;
for(int i = ; i < n; i++)
{
cin >> str;
int pos = str.find_last_of('.');
path[i] = str.substr(, pos);
type[i] = str.substr(pos);
}
string t1, t2;
for(int i = ; i < m; i++)
{
cin >> t1 >> t2;
for(int j = ; j < n; j++)
{
if(t2 != type[j]) continue;
if(t1.length() > path[j].length()) continue;
string tmp = path[j].substr(, t1.length());
if(tmp == t1) {cout << path[j] << type[j] << endl;}
}
} }
return ;
}
C FZU-2056
题意:现在有一个n*m的矩阵A,在A中找一个H*H的正方形,使得其面积最大且该正方形元素的和不大于 limit。
分析:开始以为是DP或者二维RMQ,其实用二分就可以做出来;
在输入时构造元素和矩阵dp[][](即dp[i][j]为从(1,1)到(i,j)的矩形范围元素和);再在(0,min(m,n))范围内二分查找满足条件的最优解H;
计算正方形内元素和的方法要掌握;
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn = ;
int m, n, lim;
int dp[maxn][maxn];
bool solve(int h)
{
// if(h == 1) return
for(int i = h; i <= n; i++)
{
for(int j = h; j <= m; j++)
{
if(dp[i][j]-dp[i-h][j]-dp[i][j-h]+dp[i-h][j-h] > lim) continue;
return true;
}
}
return false;
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d%d%d", &n, &m, &lim);
memset(dp, , sizeof(dp));
for(int i = ; i <= n; i++)
{
int tmp = ;
for(int j = ; j <= m; j++)
{
int x; scanf("%d", &x);
tmp += x;
dp[i][j] = dp[i-][j]+tmp;
}
} int H = min(n, m);
int L = , R = H;
int M;
while(L < R)
{
M = L+(R-L)/;
if(M == L) M++;
if(solve(M)) L = M;
else R = M-;
}
cout << L*L << endl;
}
return ;
}
D FZU-2057
题意:给出一树状家谱图,再给出两个人,问两人什么关系;
分析:又想复杂了,只要在输入时记录下父子母子关系,性别,然后由长辈往下搜就行,如果是男的就输出'F',女的输出‘M’,搜不到时注意改变长幼关系再搜一次,如果还搜不到就输出Relative;
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<stack>
using namespace std;
const int maxn = ;
int vis[maxn], child[maxn], sex[maxn];
stack<int> vv;
struct Node
{
int f, m, sex;
bool operator == (const Node& rhs) const
{
return f==rhs.f && m == rhs.m;
}
}nodes[maxn];
void print()
{
while(!vv.empty()){
int t = vv.top(); vv.pop();
if(t == ) printf("F");
else if(t == )printf("M");
}
printf("\n");
}
bool dfs(int u, int v)
{
while(!vv.empty()) vv.pop();
while(u != v)
{
if(sex[u] == )
vv.push();
else if(sex[u] == )
vv.push();
else
break;
u = child[u];
}
if(u == v)
return true;
else return false;
} int main()
{
int T; scanf("%d", &T);
while(T--)
{
memset(sex, , sizeof(sex));
int n; scanf("%d", &n);
int a, b, c;
for(int i = ; i<n/; i++)
{
scanf("%d%d%d", &a, &b, &c);
// nodes[a].f = b, nodes[a].m = c;
sex[b] = , sex[c] = ;
child[b] = child[c] = a;
}
int m; scanf("%d", &m);
while(m--)
{
int x, y; scanf("%d%d", &x, &y);
if(dfs(x, y))
{
printf("0 ");
print();
}
else if(dfs(y, x))
{
printf("1 ");
print();
}
else
printf("Relative\n");
}
}
return ;
}
E FZU-2058
题意:给出N个元素,问有多少对元素的和是M;
分析:一种常见的简单思路题;二层循环不用想肯定超时,dp当然也用不上,对于其中一个元素x,排序后用二分或者lower_bound/upper_bound函数搜索M-x的个数就好啦。
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
LL a[maxn];
LL n, m; LL solve()
{
LL cnt = ;
for(int i = ; i < n; i++)
{
LL t = m-a[i];
int pos1 = upper_bound(a+i+, a+n, t)-a-i-;
int pos2 = lower_bound(a+i+, a+n, t)-a-i-;
cnt += pos1-pos2;
}
return cnt;
} int main()
{ while(~scanf("%I64d%I64d", &n, &m))
{
for(int i = ; i < n; i++)
{
scanf("%I64d", &a[i]);
}
sort(a, a+n);
printf("%I64d\n", solve());
} return ;
}
F FZU-2059
G FZU-2060
心好累,我再想想T ^ T;
I FZU-2062
题意:要想得到1~n之间的所有数,最少需要多少个数。
分析:确实是个有点意思的水题,前提是要想到十进制可以用二进制转换啊!愚蠢!不行得多练练位运算...
以n=5为例:
5 = 1+2+2;
4 = 2+2;
3 = 1+2;
2 = 2;
1 = 1;
答案:log2(n)
J FZU-1859
题意:画图题,HDU2083的简化,递归画图就行;当然也有找规律画出来的,且待我研究研究...
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = ; int pic[maxn][maxn]; void print(int x, int y, int n)
{
if(n == ) {pic[x][y] = ''; return;}
print(x, y, n-);
print(x+(<<(n-)), y, n-);
print(x+(<<(n-)), y+(<<(n-)), n-);
} int main()
{
int T; scanf("%d", &T);
while(T--)
{
memset(pic, , sizeof(pic));
int n; scanf("%d", &n);
print(, , n);
for(int i = ; i <= (<<(n-)); i++)
{
for(int j = ; j <= i; j++)
if(pic[i][j]) printf("@"); else printf(" ");
printf("\n");
}
} return ;
}
K FZU-1862
题意:给出一个环,按顺时针的顺序求出下标为L,R之间的最大的数;
分析:这题感觉时间上自己是水过去的,把环变成数组先打表求出各区间的最大值,然后输出即可。灰常简单的转化技巧。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
int m[maxn], Max[maxn][maxn];
int main()
{
int n;
int kase = ;
while(~scanf("%d", &n))
{
printf("Case #%d:\n", ++kase);
for(int i = ; i <= n; i++) scanf("%d", &m[i]);
for(int i = ; i <= n; i++) m[n+i] = m[i];
memset(Max, -, sizeof(Max));
for(int i = ; i <= n; i++)
{
for(int j = i; j <= n+i; j++)
{
Max[i][j] = max(Max[i][j-], m[j]);
}
}
int q; scanf("%d", &q);
for(int i = ; i < q; i++)
{
int a, b; scanf("%d%d", &a, &b);
if(a <= b) printf("%d\n", Max[a][b]);
else printf("%d\n", Max[a][b+n]);
}
printf("\n");
}
return ;
}
【补】【FZU月赛】【20150515】【待续】的更多相关文章
- fzu月赛 2203 单纵大法好 二分
Accept: 8 Submit: 18Time Limit: 5000 mSec Memory Limit : 65536 KB Problem Description 人在做,天在看 ...
- FZU月赛20160416 ABEF
Problem A ABCDEFG Accept: 302 Submit: 442Time Limit: 1000 mSec Memory Limit : 32768 KB Proble ...
- Fzu月赛11 老S的旅行计划 dij
Description 老S在某城市生活的非常不自在,想趁着ICPC举办期间在省内转转.已知老S所在的省有N个城市,M条无向边(对于某一对结点可能出现重边).由于省内的交通相当糟糕,通过某条边所需要花 ...
- fzu月赛(2015.11)(思维)
Problem 2205 据说题目很水 Sunday最近对图论特别感兴趣,什么欧拉回路什么哈密顿回路,又是环又是树.在看完一本书后,他对自己特别有信心,便找到大牛牛犇犇,希望他出一题来考考自己. 在遥 ...
- 【FZU】2152 文件系统
Problem 2152 文件系统 Accept: 63 Submit: 126 Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- 【LGR-049】洛谷7月月赛
Preface Luogu八月月赛都结束了我才来补七月月赛 这次月赛还是很狗的,在绍一的晚上恰逢刮台风,然后直接打到一半断网了 结果都没有交上去GG 感觉这次难度适中,解法也比较清新自然吧,十分给个九 ...
- luogu11月月赛T3咕咕咕(组合数学)
题目描述 小 F 是一个能鸽善鹉的同学,他经常把事情拖到最后一天才去做,导致他的某些日子总是非常匆忙. 比如,时间回溯到了 2018 年 11 月 3 日.小 F 望着自己的任务清单: 看 iG 夺冠 ...
- 「P4996」「洛谷11月月赛」 咕咕咕(数论
题目描述 小 F 是一个能鸽善鹉的同学,他经常把事情拖到最后一天才去做,导致他的某些日子总是非常匆忙. 比如,时间回溯到了 2018 年 11 月 3 日.小 F 望着自己的任务清单: 看 iG 夺冠 ...
- FZU Problem 2156 Climb Stairs DP
http://acm.fzu.edu.cn/problem.php?pid=2156 题目大意: 爬楼梯,要爬到n这个位置,每次可以走x也可以走y,然后一定要经过A和B两点,求最终到达n的方案数. 思 ...
随机推荐
- 问题-Delphi2007跟踪变量时提示“E2171 Variable 'APolygon' inaccessible here due to optimization”
问题现象:Delphi2007跟踪变量时提示“E2171 Variable 'APolygon' inaccessible here due to optimization” . 问题原因:可能是因为 ...
- Storm ui 展示字段说明
1.Storm ui 首页 主要分为4块: Cluster Summary,Topology summary,Supervisor summary,Nimbus Configuration,如下图所示 ...
- HDU 5768 Lucky7 (中国剩余定理 + 容斥 + 快速乘法)
Lucky7 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...
- iOS 8版本信息与屏幕尺寸
原文 http://www.cnblogs.com/smileEvday/p/iOS8.html 1.UIWindow的bounds iOS 7之前Window的bounds不会随着方向而变化, ...
- HDU 5754 Life Winner Bo (找规律and博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754 给你四种棋子,棋子一开始在(1,1)点,两个人B和G轮流按每种棋子的规则挪动棋子,棋子只能往右下 ...
- 框架学习笔记:Unity3D的MVC框架——StrangeIoC
作为从AS3页游走过来的人,看见StrangeIoC会额外亲切,因为StrangeIoC的设计和RobotLegs几乎一致,作为一款依赖注入/控制反转(IoC)的MVC框架,StrangeIoC除了使 ...
- android4.0访问不能网络解决方法
@SuppressLint("NewApi")protected void onCreate(Bundle savedInstanceState) {StrictMode.setT ...
- JHipster的安装
JHipster GitHub地址:https://jhipster.github.io/ 刚开始接触JHipster,理解还不深,此次随笔只是把自己对JHipster的所学记录一下,也算是一种知识的 ...
- Android 4.2原生支持从右到左的文字排列格式
Android 4.1(Jelly Bean) 在TextView和EditText 元素里对“双向文字顺序”提供了有限的功能支持,允许应用程序在编辑和显示字符的时候,能够同时支持从左到右(LTR) ...
- 网络编程中常见地址结构与转换(IPv4/IPv6)
1. sockaddr/sockaddr_in/in_addr (IPv4).sockaddr6_in/in6_addr/addrinfo (IPv6) struct sockaddr { unsig ...