10 条题解
-
8
雷迪森安德镇特们,你们嚎! 别紫菜我😕 (蒟蒻恐惧)
思路
破题点:"每在等差数列后面加一个数ai,若排序后仍能构成等差数列。"
所以如果新添一个 ai,能与前面的构成等差数列,那么 gcd(ai−ai−1,公差d)=1
但如果两个数相邻且相等,它们不能被分在同一组,所以要特判
但这些还不够。如果 ai 在前面等差数列里出现过也不行,所以还得维护一个 set
代码
#include<bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; const long long mod = 1e9 + 7; void solve(){ int n; cin >> n; vector <int> a; set <int> st; for (int i = 1; i <= n; i++) cin >> a[i]; int sz = 1, d = -1; int ans = 1; st.insert(a[1]); for (int i = 2; i <= n; i++){ int cha = abs(a[i] - a[i - 1]); if (cha == 1 || cha == 0){//雪的教训 sz = 1; ans++; st.clear(); st.insert(a[i]); continue; } if (sz == 1){ sz++; d = cha; st.insert(a[i]); continue; } int td = abs(cha, d); if (td == 1 || st.find(a[i]) != st.end()){ ans ++; sz = 1; st.clear(); st.insert(a[i]); } else { sz++; d = td; st.insert(a[i]); } } cout << ans << endl; } int main(){ freopen("factory.in", "r", stdin); freopen("factory.out", "w", stdout); int test = 1; while (test--) solve(); return 0; }
WARNING
别抄!坑太多了,但思路没错(我猜你找不全)
-
chiqingrui @ 2024-10-5 15:16:43
🎉️
-
wangshijia @ 2024-10-5 15:18:43
还不是靠申书源!
-
wangshijia @ 2024-10-5 15:20:44
有坑别踩
-
xujinyang @ 2024-10-5 15:22:18
😕
-
超帅的无敌战斗小核弹 @ 2024-10-5 15:27:03
~丶~
-
超帅的无敌战斗小核弹 @ 2024-10-5 15:28:22
~丶~ ~丶~ ~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~~丶~
-
超帅的无敌战斗小核弹 @ 2024-10-5 15:28:55
~丶~ ~丶~
-
chiqingrui @ 2024-10-5 15:33:34
-
dongzhengshuo @ 2024-10-5 15:37:48
👍 👍 👍
-
dongzhengshuo @ 2024-10-5 16:17:08
为什么不是负的!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1👎
-
-
-2wangqicheng1638 LV 6 @ 2024-10-5 16:15:00
艹 写了30min 改了90min 还不如重写一遍
艹 代码:
#include<iostream> #include<bits/stdc++.h> //#include<windows.h> using namespace std; const int N = 1e6 + 1010; typedef char ch; typedef string str; typedef bool bo; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define endl "\n"; ll n, a[N]; set<ll> st; ll ans = 1; ll d = 0, td = 0; ll sz = 1; ll gcdd( ll a, ll b ) { if ( b == 0 ) { return a; } return gcdd(b, a % b); } int main() { ios::sync_with_stdio(0), cout.tie(0), cin.tie(0); // freopen( "factory.in", "r", stdin ); // freopen( "factory.out", "w", stdout ); cin >> n; // td = gcd( d, a[i] - a[i - 1] ); != 1 okabs( a[i] - a[i - 1] ) != 1 != 0ok st.find(a[i]) == true 不能加重复的 d 上一个公差 for ( ll i = 1; i <= n ; i ++ ) { cin >> a[i]; } sz = 1; ans = 1; st.insert(a[1]); for ( ll i = 2; i <= n; i ++ ) { if ( abs( a[i] - a[i - 1] ) == 1 || abs( a[i] - a[i - 1] ) == 0 ) { ans ++; //cout << "! " << a[i] << endl; sz = 1; st.clear(); st.insert(a[i]); continue; } if ( sz == 1 ) { sz ++; st.insert(a[i]); d = abs( a[i] - a[i - 1] ); continue; } td = gcdd( d, abs( a[i] - a[i - 1] ) ); //cout << i << " " << td << endl; if ( td != 1 && st.find(a[i]) == st.end() ) { sz ++; d = td; st.insert(a[i]); continue; } else { sz = 1; ans ++; //cout << "!! " << i << endl; st.clear(); st.insert(a[i]); continue; } } cout << ans << endl; return 0; }
-
-2
-
-2
-
-3
-
-3luoweichen LV 6 @ 2024-10-5 15:32:44
林楚凡干什么吃的!!你在干什么!!用vector不resize,你要干什么啊
-
wangshijia @ 2024-10-5 15:35:51
dui
-
linchufan @ 2024-10-13 8:47:20
不是,vector不用resize怎么了,push_back哪得罪你了
-
-
-4dongzhengshuo LV 2 @ 2024-10-5 14:52:26
三-
chengzhenxiang @ 2024-10-5 14:54:10
垃圾
-
chengzhenxiang @ 2024-10-5 14:55:06
-
chiqingrui @ 2024-10-5 15:19:29
-
corey0208 @ 2024-10-5 15:33:29
-
xujinyang @ 2024-10-5 15:40:34
👍
-
chengzhenxiang @ 2024-10-5 15:43:46
-
chengzhenxiang @ 2024-10-5 15:44:27
-
corey0208 @ 2024-10-5 15:45:20
-
chengzhenxiang @ 2024-10-5 15:45:57
-
chengzhenxiang @ 2024-10-5 15:47:50
-
corey0208 @ 2024-10-5 15:47:54
-
corey0208 @ 2024-10-5 15:48:07
-
chengzhenxiang @ 2024-10-5 15:49:26
-
chengzhenxiang @ 2024-10-5 15:49:26
-
chengzhenxiang @ 2024-10-5 15:49:26
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
chengzhenxiang @ 2024-10-5 15:50:02
-
xujinyang @ 2024-10-5 15:50:04
?
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:13
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:16
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
chengzhenxiang @ 2024-10-5 15:50:18
-
xujinyang @ 2024-10-5 15:51:20
我特么上午没来,没考试
-
corey0208 @ 2024-10-5 15:53:00
-
xujinyang @ 2024-10-5 15:55:43
莫名其妙挨一刀
-
chengzhenxiang @ 2024-10-5 15:55:58
-
chengzhenxiang @ 2024-10-5 15:57:34
-
-
-4zoudonghan LV 7 @ 2024-10-5 14:51:47
二-
超帅的无敌战斗小核弹 @ 2024-10-5 14:52:18
亖 -
超帅的无敌战斗小核弹 @ 2024-10-5 14:52:35
丨 -
超帅的无敌战斗小核弹 @ 2024-10-5 14:53:14
丶 -
超帅的无敌战斗小核弹 @ 2024-10-5 14:54:17
~丶~
-
超帅的无敌战斗小核弹 @ 2024-10-5 15:30:24
~丶~~丶~
-
-
-4超帅的无敌战斗小核弹 LV 3 @ 2024-10-5 14:38:53
-
chiqingrui @ 2024-10-5 14:39:48
🤣
-
超帅的无敌战斗小核弹 @ 2024-10-5 14:40:02
救不了也可以不救(
-
chiqingrui @ 2024-10-5 14:40:31
建议直接安乐🤣
-
zoudonghan @ 2024-10-5 14:50:32
20分
进步了 -
zoudonghan @ 2024-10-5 14:51:05
了 -
超帅的无敌战斗小核弹 @ 2024-10-5 14:52:00
字 -
zoudonghan @ 2024-10-5 14:52:15
亖 -
zoudonghan @ 2024-10-5 14:53:06
丨
-
dongzhengshuo @ 2024-10-5 14:54:10
《min()》
-
超帅的无敌战斗小核弹 @ 2024-10-5 14:58:03
🎉️-10纪念🎉️
-
- 1