Skip to content

Commit 7358f3f

Browse files
author
Jie Feng
committed
haha
1 parent 35f74a5 commit 7358f3f

File tree

5 files changed

+492
-3
lines changed

5 files changed

+492
-3
lines changed

yandex/Adjusting-Ducks.cpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#include <cmath>
2+
#include <set>
3+
#include <list>
4+
//#include <unordered_set>
5+
//#include <hash_map>
6+
#include <climits>
7+
#include <queue>
8+
#include <vector>
9+
#include <map>
10+
#include <set>
11+
#include <cstdlib>
12+
#include <fstream>
13+
#include <iomanip>
14+
#include <iostream>
15+
#include <sstream> // istringstream buffer(myString);
16+
#include <stack>
17+
#include <algorithm>
18+
#include <cstring>
19+
#include <cassert>
20+
using namespace std;
21+
#define bit(x,i) (x&(1<<i))
22+
#define lowb(t) (t &(-t))
23+
#define pow2(x) (1<<x)
24+
//#define max(a,b) (a<b?b:a)
25+
//#define abs(x) (x<0?-x:x)
26+
#define IN(i,l,r) (l<i&&i<r)
27+
#define LINR(i,l,r) (l<=i&&i<=r)
28+
#define LIN(i,l,r) (l<=i&&i<r)
29+
#define INR(i,l,r) (l<i&&i<r)
30+
#define F(i,L,R) for (int i = L; i < R; i++)
31+
#define FE(i,L,R) for (int i = L; i <= R; i++)
32+
#define FF(i,L,R) for (int i = L; i > R; i--)
33+
#define FFE(i,L,R) for (int i = L; i >= R; i--)
34+
#define char2Int(c) (c-'0')
35+
#define lastEle(vec) vec[vec.size()-1]
36+
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n))
37+
#define clr(a,x) memset(a,x,sizeof(a))
38+
#define getI(a) scanf("%d", &a)
39+
#define getII(a,b) scanf("%d%d", &a, &b)
40+
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
41+
#define getS(x) scanf("%s", x);
42+
#define SZ(x) ((int)((x).size()))
43+
#define REMAX(a,b) (a)=max((a),(b));
44+
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
45+
#define REMIN(a,b) (a)=min((a),(b));
46+
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
47+
#define ALL(t) t.begin(),t.end()
48+
#define ll long long
49+
#define ull unsigned long long
50+
#define ui unsigned int
51+
#define us unsigned short
52+
#define IOS ios_base::sync_with_stdio(0);
53+
#define pb push_back
54+
#define INF 1001001001
55+
#define PI 3.1415926535897932384626
56+
#define mp make_pair
57+
#define ll long long
58+
#define fi first
59+
#define se second
60+
#define root(x) ((int)sqrt((double)x))
61+
#define wez(n) int (n); scanf("%d",&(n));
62+
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
63+
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
64+
inline void pisz(int n) { printf("%d\n",n); }
65+
#define TESTS wez(testow)while(testow--)
66+
#define whileZ int T; getI(T); while(T--)
67+
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
68+
#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;}
69+
#define printV(a) printA(a,0,(int)a.size()-1);
70+
#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;}
71+
#define MAXN 10000
72+
#define sz(a) int((a).size())
73+
#define pb push_back
74+
#define all(c) (c).begin(),(c).end()
75+
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
76+
#define present(c,x) ((c).find(x) != (c).end())
77+
#define cpresent(c,x) (find(all(c),x) != (c).end())
78+
template<class T> string tos(T n) { stringstream ss; ss << n; return ss.str(); }
79+
#define tiny (double)1e-13
80+
#define close(x,y) (abs(x-y)<tiny)
81+
typedef int elem_t;
82+
typedef vector<int> vi;
83+
typedef vector<vi> vvi;
84+
typedef pair<int,int> ii;
85+
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
86+
template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; }
87+
int gcd(int a,int b){return a?gcd(b%a,a):b;}
88+
ll gcd(ll a,ll b){return a?gcd(b%a,a):b;}
89+
ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;}
90+
const int fx[4][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}};
91+
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
92+
#define N (int)1e5+10
93+
int a[N];
94+
ll f[N];
95+
int n;
96+
int main ( int argc, char *argv[] ) {
97+
cin >> n;
98+
FE(i,1,n) getI(a[i]);
99+
100+
sort(a+1, a+n+1);
101+
ll sum = 0;
102+
103+
FE(i,0,n) f[i] = 1e14;
104+
105+
106+
f[0] = 0;
107+
108+
f[2] = abs(a[1] - a[2]);
109+
if (n == 2){
110+
cout << f[2] << endl;
111+
return 0;
112+
}
113+
114+
f[3] = abs(a[2] - a[3]) + f[2];
115+
if (n == 3){
116+
cout << f[3] << endl;
117+
return 0;
118+
}
119+
120+
FE(i,4,n){
121+
f[i] = min(f[i-2] + abs(a[i-1]-a[i]),
122+
f[i-3] + abs(a[i-2]-a[i-1]) + abs(a[i-1]-a[i])
123+
);
124+
}
125+
cout << f[n] << endl;
126+
return EXIT_SUCCESS;
127+
}

yandex/Concave.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include <cmath>
2+
#include <set>
3+
#include <list>
4+
//#include <unordered_set>
5+
//#include <hash_map>
6+
#include <climits>
7+
#include <queue>
8+
#include <vector>
9+
#include <map>
10+
#include <set>
11+
#include <cstdlib>
12+
#include <fstream>
13+
#include <iomanip>
14+
#include <iostream>
15+
#include <sstream> // istringstream buffer(myString);
16+
#include <stack>
17+
#include <algorithm>
18+
#include <cstring>
19+
#include <cassert>
20+
using namespace std;
21+
#define bit(x,i) (x&(1<<i))
22+
#define lowb(t) (t &(-t))
23+
#define pow2(x) (1<<x)
24+
//#define max(a,b) (a<b?b:a)
25+
//#define abs(x) (x<0?-x:x)
26+
#define IN(i,l,r) (l<i&&i<r)
27+
#define LINR(i,l,r) (l<=i&&i<=r)
28+
#define LIN(i,l,r) (l<=i&&i<r)
29+
#define INR(i,l,r) (l<i&&i<r)
30+
#define F(i,L,R) for (int i = L; i < R; i++)
31+
#define FE(i,L,R) for (int i = L; i <= R; i++)
32+
#define FF(i,L,R) for (int i = L; i > R; i--)
33+
#define FFE(i,L,R) for (int i = L; i >= R; i--)
34+
#define char2Int(c) (c-'0')
35+
#define lastEle(vec) vec[vec.size()-1]
36+
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n))
37+
#define clr(a,x) memset(a,x,sizeof(a))
38+
#define getI(a) scanf("%d", &a)
39+
#define getII(a,b) scanf("%d%d", &a, &b)
40+
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
41+
#define getS(x) scanf("%s", x);
42+
#define SZ(x) ((int)((x).size()))
43+
#define REMAX(a,b) (a)=max((a),(b));
44+
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
45+
#define REMIN(a,b) (a)=min((a),(b));
46+
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
47+
#define ALL(t) t.begin(),t.end()
48+
#define ll long long
49+
#define ull unsigned long long
50+
#define ui unsigned int
51+
#define us unsigned short
52+
#define IOS ios_base::sync_with_stdio(0);
53+
#define pb push_back
54+
#define INF 1001001001
55+
#define PI 3.1415926535897932384626
56+
#define mp make_pair
57+
#define ll long long
58+
#define fi first
59+
#define se second
60+
#define root(x) ((int)sqrt((double)x))
61+
#define wez(n) int (n); scanf("%d",&(n));
62+
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
63+
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
64+
inline void pisz(int n) { printf("%d\n",n); }
65+
#define TESTS wez(testow)while(testow--)
66+
#define whileZ int T; getI(T); while(T--)
67+
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
68+
#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;}
69+
#define printV(a) printA(a,0,(int)a.size()-1);
70+
#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;}
71+
#define MAXN 10000
72+
#define sz(a) int((a).size())
73+
#define pb push_back
74+
#define all(c) (c).begin(),(c).end()
75+
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
76+
#define present(c,x) ((c).find(x) != (c).end())
77+
#define cpresent(c,x) (find(all(c),x) != (c).end())
78+
template<class T> string tos(T n) { stringstream ss; ss << n; return ss.str(); }
79+
#define tiny (double)1e-13
80+
#define close(x,y) (abs(x-y)<tiny)
81+
typedef int elem_t;
82+
typedef vector<int> vi;
83+
typedef vector<vi> vvi;
84+
typedef pair<int,int> ii;
85+
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
86+
template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; }
87+
int gcd(int a,int b){return a?gcd(b%a,a):b;}
88+
ll gcd(ll a,ll b){return a?gcd(b%a,a):b;}
89+
ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;}
90+
const int fx[4][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}};
91+
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
92+
int n;
93+
int a[10000];
94+
int main ( int argc, char *argv[] ) {
95+
cin >> n;
96+
F(i,0,n) getI(a[i]);
97+
if (n <= 3){
98+
cout << -1 << endl;
99+
return 0;
100+
}
101+
sort(a, a+n);
102+
int i;
103+
for (i = n-1; i >= 3; i--){
104+
if (a[i] < a[i-1] + a[i-2] + a[i-3]){
105+
if (!(a[i] == a[i-1] && a[i] == a[i-2] && a[i] == a[i-3])){
106+
break;
107+
}
108+
}
109+
}
110+
if (i == 2) cout << -1 << endl;
111+
else cout << a[i] + a[i-1] + a[i-2] + a[i-3] << endl;
112+
113+
return EXIT_SUCCESS;
114+
}

yandex/Learning-to-Add.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <cmath>
2+
#include <set>
3+
#include <list>
4+
//#include <unordered_set>
5+
//#include <hash_map>
6+
#include <climits>
7+
#include <queue>
8+
#include <vector>
9+
#include <map>
10+
#include <set>
11+
#include <cstdlib>
12+
#include <fstream>
13+
#include <iomanip>
14+
#include <iostream>
15+
#include <sstream> // istringstream buffer(myString);
16+
#include <stack>
17+
#include <algorithm>
18+
#include <cstring>
19+
#include <cassert>
20+
using namespace std;
21+
#define bit(x,i) (x&(1<<i))
22+
#define lowb(t) (t &(-t))
23+
#define pow2(x) (1<<x)
24+
//#define max(a,b) (a<b?b:a)
25+
//#define abs(x) (x<0?-x:x)
26+
#define IN(i,l,r) (l<i&&i<r)
27+
#define LINR(i,l,r) (l<=i&&i<=r)
28+
#define LIN(i,l,r) (l<=i&&i<r)
29+
#define INR(i,l,r) (l<i&&i<r)
30+
#define F(i,L,R) for (int i = L; i < R; i++)
31+
#define FE(i,L,R) for (int i = L; i <= R; i++)
32+
#define FF(i,L,R) for (int i = L; i > R; i--)
33+
#define FFE(i,L,R) for (int i = L; i >= R; i--)
34+
#define char2Int(c) (c-'0')
35+
#define lastEle(vec) vec[vec.size()-1]
36+
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n))
37+
#define clr(a,x) memset(a,x,sizeof(a))
38+
#define getI(a) scanf("%d", &a)
39+
#define getII(a,b) scanf("%d%d", &a, &b)
40+
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
41+
#define getS(x) scanf("%s", x);
42+
#define SZ(x) ((int)((x).size()))
43+
#define REMAX(a,b) (a)=max((a),(b));
44+
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
45+
#define REMIN(a,b) (a)=min((a),(b));
46+
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
47+
#define ALL(t) t.begin(),t.end()
48+
#define ll long long
49+
#define ull unsigned long long
50+
#define ui unsigned int
51+
#define us unsigned short
52+
#define IOS ios_base::sync_with_stdio(0);
53+
#define pb push_back
54+
#define INF 1001001001
55+
#define PI 3.1415926535897932384626
56+
#define mp make_pair
57+
#define ll long long
58+
#define fi first
59+
#define se second
60+
#define root(x) ((int)sqrt((double)x))
61+
#define wez(n) int (n); scanf("%d",&(n));
62+
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
63+
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
64+
inline void pisz(int n) { printf("%d\n",n); }
65+
#define TESTS wez(testow)while(testow--)
66+
#define whileZ int T; getI(T); while(T--)
67+
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
68+
#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;}
69+
#define printV(a) printA(a,0,(int)a.size()-1);
70+
#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;}
71+
#define MAXN 10000
72+
#define sz(a) int((a).size())
73+
#define pb push_back
74+
#define all(c) (c).begin(),(c).end()
75+
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
76+
#define present(c,x) ((c).find(x) != (c).end())
77+
#define cpresent(c,x) (find(all(c),x) != (c).end())
78+
template<class T> string tos(T n) { stringstream ss; ss << n; return ss.str(); }
79+
#define tiny (double)1e-13
80+
#define close(x,y) (abs(x-y)<tiny)
81+
typedef int elem_t;
82+
typedef vector<int> vi;
83+
typedef vector<vi> vvi;
84+
typedef pair<int,int> ii;
85+
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
86+
template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; }
87+
int gcd(int a,int b){return a?gcd(b%a,a):b;}
88+
ll gcd(ll a,ll b){return a?gcd(b%a,a):b;}
89+
ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;}
90+
const int fx[4][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}};
91+
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
92+
int A[5];
93+
int n;
94+
int MMM;
95+
void go(int a, int lev){
96+
// cout << lev << ' ' << a << endl;
97+
if (lev == n){
98+
MMM = max(MMM, a);
99+
return;
100+
}
101+
a += A[lev];
102+
103+
string sa = tos(a);
104+
105+
sort(sa.begin(), sa.end());
106+
do{
107+
istringstream buffer(sa);
108+
int aa;
109+
buffer >> aa;
110+
go(aa, lev+1);
111+
}while(next_permutation(sa.begin(), sa.end()));
112+
}
113+
int main ( int argc, char *argv[] ) {
114+
getI(n);
115+
F(i,0,n) getI(A[i]);
116+
MMM = INT_MIN;
117+
go(0, 0);
118+
cout << MMM << endl;
119+
return EXIT_SUCCESS;
120+
}

yandex/in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
2
2-
1 2
3-
1 2
1+
5
2+
42 1 3 3 6

0 commit comments

Comments
 (0)