比赛链接:牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ
A-小红的直角三角形_牛客周赛 Round 109
签到题:用勾股定理即可通过此题(需要注意对共线情况的判断)
代码:
// Problem: 小红的直角三角形
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/116945/A
// Memory Limit: 2048 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int x,y,xx,yy;cin>>x>>y>>xx>>yy;int a = x * x + y * y;int b = xx * xx + yy * yy;if(y == yy && y == 0 || x == xx && x == 0){NOreturn ;}int c = (xx - x) * (xx - x) + (yy - y) * (yy - y);if(a + b == c || a + c == b || b + c == a) YESelse NO
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;
// cin>>T;while(T--) solve(); return 0;
}
B-小红的好点对_牛客周赛 Round 109
乍一看题目很好读懂,但是想不到很好的算法来实现,然后再看一眼数据范围,才100个点,好了,一道语法题,用暴力去遍历即可通过。
// Problem: 小红的好点对
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/116945/B
// Memory Limit: 2048 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18;
bool ok(pii x,pii y)
{int x1 = x.fi,y1 = x.se;int x2 = y.fi,y2 = y.se;double dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));if(dis - 1.0) return false;return true;
}
void solve()
{int n;cin>>n;vector<pii> a(n+1);for(int i=1;i<=n;i++) cin>>a[i].fi>>a[i].se;int ans = 0;for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){if(ok(a[i],a[j])) ans ++;}}cout<<ans<<endl;
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;
// cin>>T;while(T--) solve(); return 0;
}
C-小红的整数三角形_牛客周赛 Round 109
这道题就比较有意思了,要求是让你找到一个点C,然后使得ABC三个点组成的三角形的面积是一个正整数,而且坐标也要是正整数,那么我们可以在纸上画一画就不难发现:当已知的两个点AB共线的时候,这条边AB就可以作为三角形的底边,那么我们只需要让点C到AB的距离是一个正整数就行了,很容易就能想出来让点C在点A或点B的正上方或者正下方即可。
那么如果A,B两点不共线呢?那我们就可以让AB这条线作为一个直角三角形的斜边,也就是A和B所围成的矩形的斜对角线,那么这个时候的点C只要在A或B的正下方或者正上方就行了。
// Problem: 小红的整数三角形
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/116945/C
// Memory Limit: 2048 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int x1,x2,y1,y2;cin>>x1>>y1>>x2>>y2;int dx = x2 - x1;int dy = y2 - y1;if(dx){if(dx % 2 == 0) cout<<x1<<' '<<y1 + 1<<endl;else cout<<x1<<' '<<y1 + 2<<endl;}else{if(dy % 2 == 0) cout<<x1 + 1<<' '<<y1<<endl;else cout<<x1 + 2<<' '<<y1<<endl;}
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;
// cin>>T;while(T--) solve(); return 0;
}
D-小红的马_牛客周赛 Round 109
这道题初看没有什么思路,我一开始是想着遍历每一个可以放马的点,但是想不到怎么去确定这几个点,所以我们不妨用逆向思维来解决这道题:我们是知道每一个兵的坐标的,那么我们就可以根据每一个兵的坐标来存可能的马的放置点的坐标,因为这个点放马的话这个马就可以吃这个兵,那么反过来也就是这个位置上的兵能够被这个位置的马吃,所以我们就可以根据这n个兵的位置,累加每个点的八个方向的点,然后最后再统计出最大的即可。
一定要注意在最后的遍历统计的时候要对坐标的合法性进行分析,因为有减法所以可能导致出现不合法的坐标的出现!
// Problem: 小红的马
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/116945/D
// Memory Limit: 2048 MB
// Time Limit: 6000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n;cin>>n;vector<pii> a(n+1);map<pii,int> mp;for(int i=1;i<=n;i++){cin>>a[i].fi>>a[i].se;int x = a[i].fi,y = a[i].se;mp[{x-1,y+2}] ++;mp[{x+1,y+2}] ++;mp[{x+2,y+1}] ++;mp[{x+2,y-1}] ++;mp[{x+1,y-2}] ++;mp[{x-1,y-2}] ++;mp[{x-2,y-1}] ++;mp[{x-2,y+1}] ++;}int anx = -1,any = -1,num = 0;for(auto & i : mp){int sum = i.se;if(sum > num && i.fi.fi > 0 && i.fi.se > 0){num = sum;auto t = i.fi;anx = t.fi;any = t.se;}}cout<<anx<<' '<<any<<endl;
// cout<<fixed<<setprecision(x)<< ;
}signed main()// Don't forget pre_handle!
{IOSint T=1;
// cin>>T;while(T--) solve(); return 0;
}