Mendo Judge Discussion Board - Forums
Search
Recent Topics
Hottest Topics
Member Listing
Back to home page
Messages posted by: Theo830
Forum Index
»
Profile for Theo830
»
Messages posted by Theo830
Author
Message
Задачи од меѓународни натпревари
»
Pawns
»
Go to message
solution c++:
#include <iostream> #include <cstring> #include <vector> #include <set> #include <map> #include <sstream> #include <cstdio> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <iomanip> #include <fstream> //#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = (1 << 30); const ll inf = (1LL << 60LL); int n; int arr[15]; bool check(string s){ if(s[0] == '1'){ int idx = -1; for(int i = 0; i < (int)s.size(); i ++){ if(s[i] != '1'){ idx = i; break; } } if(idx != -1){ while(s[idx] == '0'){ idx ++; } for(int i = idx; i < (int)s.size(); i ++){ if(s[i] != '2'){ return false; } } } return true; } return false; } map<string, bool> visited; map<int, int> backtrack; int main(int argc, const char * argv[]) { ios_base::sync_with_stdio(false); cin >> n; string s = ""; for(int i = 0; i < n; i ++){ cin >> arr[i]; s += (char)(arr[i] + '0'); } string A = s; queue<string> q; q.push(s); queue<int> qCekor; qCekor.push(0); queue<vector<int> > qv; vector<int> a; qv.push(a); int cekor; int ret = INF; string tmp; while(!q.empty()){ s = q.front(); q.pop(); cekor = qCekor.front(); qCekor.pop(); a = qv.front(); qv.pop(); if(check(s)){ cout << cekor << "\n"; for(int i = 0; i <(int)a.size(); i ++){ cout << a[i] << " "; } return 0; } for(int i = 0; i < (int)s.size(); i ++){ if(s[i] == '1'){ if(i - 1 >= 0 and s[i - 1] == '0'){ tmp = s; tmp[i] = '0'; tmp[i - 1] = '1'; if(visited[tmp])continue; visited[tmp] = true; q.push(tmp); qCekor.push(cekor + 1); vector<int> b = a; b.push_back(i + 1); qv.push(b); } if(i - 2 >= 0 and s[i - 1] != '0' and s[i - 2] == '0'){ tmp = s; tmp[i] = '0'; tmp[i - 2] = '1'; if(visited[tmp])continue; visited[tmp] = true; q.push(tmp); qCekor.push(cekor + 1); vector<int> b = a; b.push_back(i + 1); qv.push(b); } } else if(s[i] == '2'){ if(i + 1 < n and s[i + 1] == '0'){ tmp = s; tmp[i] = '0'; tmp[i + 1] = '2'; if(visited[tmp])continue; visited[tmp] = true; q.push(tmp); qCekor.push(cekor + 1); vector<int> b = a; b.push_back(i + 1); qv.push(b); } if(i + 2 < n and s[i + 1] != '0' and s[i + 2] == '0'){ tmp = s; tmp[i] = '0'; tmp[i + 2] = '2'; if(visited[tmp])continue; visited[tmp] = true; q.push(tmp); qCekor.push(cekor + 1); vector<int> b = a; b.push_back(i + 1); qv.push(b); } } } } return 0; }
Задачи од меѓународни натпревари
»
Big Circle JBOI 2014
»
Go to message
solution c++:
#include <stdio.h> #include <math.h> #include <algorithm> using namespace std; #define eps 0.000001 struct point { double x,y; } points[333555]; double dist(point p1, point p2) { return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y)); } bool cmp(point p1, point p2) { double u1,u2; if (fabs(p1.y - points[0].y) < eps) return false; if (fabs(p2.y - points[0].y) < eps) return true; u1 = (p1.x - points[0].x) / (p1.y - points[0].y); u2 = (p2.x - points[0].x) / (p2.y - points[0].y); return (u1 < u2); } int main() { int n,p,i; double d,res; point tmp; scanf("%d", &n); p = 0; for(i=0; i<n; i++) { scanf("%lf%lf", &points[i].x, &points[i].y); if (points[i].y < points[p].y || (fabs(points[i].y - points[p].y) < eps && points[i].x < points[p].x) ) { p = i; } } tmp = points[0]; points[0] = points[p]; points[p] = tmp; sort(points+1,points+n,cmp); res = dist(points[0], points[n-1]); for(i=1; i<n; i++) { d = dist(points[i], points[i-1]); if (d < res) res = d; } printf("%.2lf\n", res); return 0; }
Задачи од меѓународни натпревари
»
JBOI-Samba
»
Go to message
if someone wants the solution of Samba jboi 2011 (please do not copy patse):
#include <bits/stdc++.h> #define FOR(i,a,b) for(i=a; i<=b; i++) #define MAXN 1000000 using namespace std; int A[MAXN+5]; int solve() { int K,N,i,k; scanf("%d %d",&N,&K); FOR(i,1,N) scanf("%d",A+i); sort(A+1,A+N+1); FOR(i,1,N) { k = i++; while(A[i] == A[k] && i <= N) i++; if((i-k)%K) return A[k]; i--; } } int main() { printf("%d\n",solve()); return 0; }
Forum Index
»
Profile for Theo830
»
Messages posted by Theo830
Go to:
Select a forum
Добродојдовте!
Општа дискусија
Задачи од национални натпревари
Задачи од меѓународни натпревари
Други задачи
Регионални натпревари
Државни натпревари
Македонски Олимпијади
Други натпревари
Pascal
C/C++
Јава
Други јазици
Powered by
JForum 2.1.8
©
JForum Team