Codeforces Round #420 (Div.2)
来源:互联网 发布:迅雷水晶矿场软件 编辑:程序博客网 时间:2024/06/06 14:03
A.
题意:n x n的矩阵,对于每一个不是1的数字,如果都能找到一个与它同行的数字和一个与它同列的数字使得二者的和为这个数字,输出Yes,否则输出No
解题思路:遍历,找到不等于1的数字,用两个一维数组将与这个数字同行、同列的数字分别存储起来,遍历这两个数组判断二者之和是否等于这个数字
代码:
#include <iostream>#include <algorithm>#include <cstring>#include <string>#include <cstdio>using namespace std;int n,a[55][55];bool solve(int x,int y,int k){ int b[55],c[55]; for(int i=0;i<n;i++) { b[i]=a[x][i]; c[i]=a[i][y]; } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(b[i]+c[j]==k)return true; } } return false;}int main(){ scanf("%d",&n); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { scanf("%d",&a[i][j]); } } int ok=1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i][j]!=1) if(!solve(i,j,a[i][j])) ok=0; } } if(ok)printf("Yes\n"); else printf("No\n"); return 0;}
题意:给定直线y=-x/m+b,整数m、b。对于整数点(x,y),0<=x,y矩形范围内的每个整点有x+y个香蕉,其他点没有香蕉,求收获香蕉的最大数目
解题思路:由直线方程得x=my+b,ymax=b。枚举0~b的整数y可求得每个y对应的整数x,用等差数列分别计算x、y的总和,共有(y+1)个x的总和,(x+1)个y的总和,循环更新最大值,注意用long long int
代码:
#include <bits/stdc++.h>using namespace std;typedef long long int ll;int main(){ ll m,b; while(cin>>m>>b) { ll ans=0; for(ll y=0;y<=b;y++)//y是整数 { ll x=(b-y)*m;//x也是整数 ll k=x*(1+x)/2*(y+1)+y*(1+y)/2*(x+1);//x+y,把x和y分别算 ans=max(ans,k); } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- Codeforces Round #420 (Div. 2)
- Codeforces Round #420 (Div. 2)
- Codeforces Round #420 (Div. 2)
- Codeforces Round #420 (Div.2)
- Codeforces Round #420 (Div. 2)
- Codeforces Round #420 (Div. 2)(A+B)
- Codeforces Round #420 (Div. 2) C
- Codeforces Round #420 (Div. 2)总结
- Codeforces Round #420 (Div. 2) D
- Codeforces Round #420 (Div. 2) 821
- Codeforces Round #420 (Div. 2) 题解
- Codeforces Round #420 (Div. 2) 821C
- [刷题]Codeforces Round #420(Div. 2)
- [刷题]Codeforces Round #420(Div. 2)
- 【Codeforces Round #420 (Div. 2)】Codeforces 821ABCDE
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- 高并发服务器
- YouCompleterMe:No semantic completer exists for filetypes:['cpp']
- 10. 软件发布
- 小白的2017书单(三)前端
- Android判断设备是手机还是平板
- Codeforces Round #420 (Div.2)
- 判断单链表是否形成环形结构,快慢指针
- weight和weightSum
- java线程
- Lintcode78 Longest Common On Prefix solution 题解
- 【脚本语言系列】关于Python容器,你需要知道的事
- 11. fae来协助调试_办法
- Web图书管理系统---分页、上传、下载、增删改查
- html事件(onclick、onchange等)传对象作为参数