比賽鏈接:牛客競賽_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;
}