Codeforces Round #194 (Div. 2) 部分题解
http://codeforces.com/contest/334
A题意:1-n^2 平均分成 n 份,每份n个数,且和相同
解法 : 构造矩阵1-n^2的矩阵即可
int a[][];
int main()
{
int n;
scanf("%d",&n);
int k = n*n;
int c = ;
for(int i = ; i < n ; i++)
for(int j = ; j < n ; j++)
a[i][j] = c++;}
for(int i = ; i < n ; i++)
{
for(int j = ; j < n ; j++)
printf("%d ",a[j][(i+j)%n]);
puts("");
}
return ;
}
B:8个点能否关于矩形对称
解法: 直接暴力判断8个点,注意判重
struct point
{
int x,y;
}p[];
int cmp(point a,point b){
if(a.x == b.x) return a.y<b.y;
return a.x < b.x;
}
int main()
{
for(int i = ; i < ; i++)
cin>>p[i].x>>p[i].y;
sort(p,p+,cmp);
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
if(i != j && p[i].x == p[j].x && p[i].y == p[j].y)
{
cout<<"ugly"<<endl;
return ;
}
if(p[].x == p[].x && p[].x == p[].x && p[].x == p[].x
&& p[].x == p[].x && p[].x == p[].x)
{
if(p[].y == p[].y && p[].y == p[].y && p[].y == p[].y
&& p[].y == p[].y && p[].y == p[].y)
cout<<"respectable"<<endl;
else cout<<"ugly"<<endl;
}else cout<<"ugly"<<endl;
return ;
}
C题意: 用面值为3的次幂的硬币 购买价值为n的商品 , 要求硬币总价值>n且硬币数最多且这些硬币的子集不能>=n
解法 : 贪心,如果非3的倍数一定是n/3+1 即全换成3
否则就不能换成3要换成面值更大的 以此类推直到不为3^k为止
int main() {
LL n;
cin>>n;
while(n % == ) n /= ;
cout<<(n/)+<<endl;
}
D题意: 在n*n矩阵中 有一些不能走的格子, 从边界(非顶角)出发 能直线走到对面边界的最多方案数
解法 : 如果中间没有不能走的格子 ,对于在(x,x)上相交的十字形一共有2种不冲突的放法
可以证出: 其中一定存在一种对其他情况不影响走法 ----------------------------------画图可归纳
奇数情况特判中间点即可
bool bx[],by[];
int n,m;
int main()
{
//freopen("in.txt","r",stdin);
cin>>n>>m;
while(m--)
{
int x,y;
cin>>x>>y;
bx[x] = ;
by[y] = ;
}
int res = ;
for(int i = ; i < n ; i++)
{
if(bx[i] == ) res++;
if(by[i] == ) res++;
}
if(n% == && bx[n/+] == && by[n/+] == ) res--;
cout<<res<<endl;
return ;
}
Codeforces Round #194 (Div. 2) 部分题解的更多相关文章
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
随机推荐
- HDU 4714 Tree2cycle(树型DP)
解题思路: 将一棵树变成一个环.假设一个结点的分叉数目大于等于2.则将它与父节点断开.而且断开子结点数目sum - 2条边,并再次连接sum-2个儿子形成一条直链然后这条游离链与还有一条游离链相连,共 ...
- 对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了
对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了 太阳火神的漂亮人生 (http:// ...
- POJ 3450--Corporate Identity【KMP && 枚举】
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5696 Accepted: 207 ...
- 识别CentOS和Ubuntu的系统版本
识别CentOS和Ubuntu的系统版本1.用 lsb-release#!/bin/bashInstall_LSB(){ if [ "$PM" = "yum ...
- java中replaceAll反斜杠\ or java中replaceAll 括号[
java中replaceAll反斜杠\ String s=new String("this is a \\"); s.replaceAll("\\",&qu ...
- codefroces 873 B. Balanced Substring && X73(前缀和思想)
B. Balanced Substring You are given a string s consisting only of characters 0 and 1. A substring [l ...
- 各消息队列对比,Kafka深度解析,众人推荐,精彩好文!
http://blog.csdn.net/allthesametome/article/details/47362451
- js正則表達式--验证表单
检測手机号码:/0? (13|14|15|18)[0-9]{9}/ 检測username:(数字,英文,汉字.下划线.中横线):/^[A-Za-z0-9_\-\u4e00-\u9fa5]+$/ pas ...
- Python 值传递和引用传递
值传递和引用传递 參考地址:http://www.dataguru.cn/thread-489552-1-1.html python的值传递不会改变传入參数的值,而引用传递传入的是一个地址.有点相似c ...
- express中的中间件理解
什么是中间件 中间件是一个可访问请求对象(req)和响应对象(res)的函数,在 Express 应用的请求-响应循环里,下一个内联的中间件通常用变量 next 表示.中间件的功能包括: 执行任何代码 ...