Последен тест#
#include <iostream> using namespace std; int main() { double d=0; int i,a1,a2,a3,a4,o,pr; cin>>o; if(o==2) pr=60; else if(o==3) pr=70; else if(o==4) pr=80; else pr=90; cin>>a1>>a2>>a3>>a4; d=(a1+a2+a3+a4); for(i=0;i<=100;i++) { d+=i; if(d/5>=pr) { cout<<i<<endl; return 0; } d-=i; } cout<<"GRESHKA"<<endl; return 0; }
Подароци#
#include <iostream> #include<sstream> #include<cstring> #include<string> #include<iomanip> #include<stdio.h> #include<queue> #include<vector> #include<list> #include<map> #include<algorithm> #include<cmath> #include<math.h> #define pb push_back #define MS(a,y) memset(a,y,sizeof(a)) using namespace std; int di[4]={1,-1,0,0},dy[4]={0,0,1,-1}; int main() { int a[150],n,i,j=0,k,ans=0; cin>>n; for(i=0;i<n;i++) {cin>>a[i]; j+=a[i];} if(j%n!=0) { cout<<"GRESHKA"<<endl; return 0; } for(i=0;i<n;i++) if(a[i]>j/n) ans+=a[i]-j/n; cout<<ans<<endl; return 0; }
Спојување#
#include <iostream> #include<sstream> #include<cstring> #include<string> #include<iomanip> #include<stdio.h> #include<fstream> #include<queue> #include<vector> #include<list> #include<map> #include<algorithm> #include<cmath> #include<math.h> #define pb push_back #define MS(a,y) memset(a,y,sizeof(a)) using namespace std; int main() { int n,nzs=0,gol=0; cin>>n; string niz[1010],naz[1010]; for(int i=0;i<n;i++) { cin>>niz[i]; naz[i]=niz[i]; if(gol<niz[i].size()) gol=niz[i].size(); } nzs=gol; stringstream res; for(int i=0;i<n;i++) { int z=niz[i].size(); while(nzs%z!=0) nzs+=gol; } for(int i=0;i<n;i++) { gol=nzs/niz[i].size(); while(gol--) { naz[i]+=niz[i]; } } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(naz[i]<naz[j]) { swap(niz[i],niz[j]); swap(naz[i],naz[j]); } } } for(int i=0;i<n;i++) res<<niz[i]; cout<<res.str()<<endl; return 0; }
Порака#
#include <iostream> #include<sstream> #include<cstring> #include<string> #include<iomanip> #include<stdio.h> #include<queue> #include<vector> #include<list> #include<map> #include<algorithm> #include<cmath> #include<math.h> #define pb push_back #define MS(a,y) memset(a,y,sizeof(a)) using namespace std; int main() { int n,k,e,cur=0,i,j,ans=0; cin>>n>>k; string a; cin>>a; for(e=0;e<k;e++){ int d=999999; for(i=0;i<a.size();i+=k) { cur=0; for(j=0;j<a.size();j+=k) { int ni=i+e,nj=j+e; if(i==j) continue; if(a[ni]!=a[nj]) cur++; } d=min(d,cur); } ans+=d; } cout<<ans; return 0; }
Коцки#
#include <iostream> #include<sstream> #include<cstring> #include<string> #include<iomanip> #include<stdio.h> #include<queue> #include<vector> #include<list> #include<map> #include<algorithm> #include<cmath> #include<math.h> #define pb push_back #define MS(a,y) memset(a,y,sizeof(a)) using namespace std; int main() { long long n,i,j,k,dp[90]; cin>>n; MS(dp,0); dp[3]=1; for(i=4;i<=n;i++) { dp[i]++; for(j=3;j<i;j++) dp[i]+=i-j+1; for(k=3;k<=n;k++) for(j=i-k-1;j>0;j--) dp[i]+=dp[j]; } cout<<dp[n]+1<<endl; return 0; }
Оценување#
#include <iostream> #include<string> #include<cstring> #include<sstream> #include<vector> #include<algorithm> #include<climits> using namespace std; long long n,k,ar[31],ans=LONG_LONG_MAX; bool cc(long long a) { long long t = 0; for(int i=0;i<n;i++) t+=a/ar[i]; if(t>=k) { ans=min(a,ans); return true; } return false; } void BS(long long a, long long b) { long long c=(a/2)+(b/2); bool t=cc(c); if(a!=b & c!=a & c!=b) { if(t) { BS(a,c); } else { BS(c,b); } } } int main() { cin>>n>>k; for(int i=0;i<n;i++) cin>>ar[i]; BS(0,LONG_LONG_MAX); cout<<ans<<endl; return 0; }
Лавиринт#
#include <iostream> #include<sstream> #include<cstring> #include<string> #include<iomanip> #include<stdio.h> #include<queue> #include<vector> #include<list> #include<map> #include<algorithm> #include<cmath> #include<math.h> #define pb push_back #define MS(a,y) memset(a,y,sizeof(a)) using namespace std; int di[4]={1,-1,0,0},dj[4]={0,0,1,-1}; char mat[310][310]; int n,m,pi,pj,ei,ej,ans=999999; int dp[310][310][4]; queue<int> qi,qj,qc,t; void input() { cin>>n>>m; int i,j,k,l; for(i=0;i<n;i++) for(j=0;j<m;j++) { cin>>mat[i][j]; if(mat[i][j]=='P') { pi=i; pj=j; } else if(mat[i][j]=='K') { ei=i; ej=j; } } } void output() { for(int i=1;i<4;i++) if(dp[ei][ej][i]!=-1) ans=min(ans,dp[ei][ej][i]); cout<<ans<<endl; } bool isvalid(int r,int i, int j,int ri, int rj,int c) { for(int k=1;k<=r;k++) { int ni=i+ri*k,nj=j+rj*k; if(ni<0 || ni>=n || nj<0 || nj>=m) return false; if(mat[ni][nj]=='#') return false; } return true; } void bfs() { int i,j,k,l; MS(dp,-1); qi.push(pi); qj.push(pj); qc.push(0); t.push(1); dp[pi][pj][1]=0; int c,r; while(!qi.empty()) { i=qi.front(),j=qj.front(),c=qc.front(),r=t.front(); qi.pop(),qj.pop(),qc.pop(),t.pop(); for(k=0;k<4;k++) { int ni=i+di[k]*r,nj=j+dj[k]*r; if(isvalid(r,i,j,di[k],dj[k],c)) if(dp[ni][nj][r]==-1 || c+1<dp[ni][nj][r]) { dp[ni][nj][r]=c+1; qi.push(ni); qj.push(nj); qc.push(c+1); t.push(r%3+1); } } } } int main() { input(); bfs(); output(); return 0; }
--Филип Беџовски
Множење, Олимпијада#
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <math.h> using namespace std; int gol=0; string mn(string a,string b) { string s; int i,j,k; vector<string> n,m; k=b.size(); for(i=a.size()-1; i>=0; i--) { string tmp="0"; for(j=0;j<=b.size();j++) tmp+='0'; for(j=b.size()-1; j>=0; j--) { int k=a[i]-48; int q=b[j]-48; k*=q; tmp[j+1]+=(k%10); tmp[j]+=(k/10); while(tmp[j+1]>'9') { tmp[j+1]-=10; tmp[j]++; } while(tmp[j]>'9') { tmp[j-1]++; tmp[j]-=10; } } string uber; for(j=0; j<=k+3; j++) uber+='0'; tmp=uber+tmp; int size=tmp.size(); gol=max(gol,size); while(tmp.size()<gol-1) tmp+='0'; k--; n.push_back(tmp); } s=n[0]; s.resize(gol*gol); for(i=1; i<n.size(); i++) { string tmp=n[i]; for(j=n[i].size()-1; j>0; j--) { if(s[j]>'9') { s[j]-=10; s[j-1]++; } s[j]+=tmp[j]-48; if(s[j]>'9') { s[j]-=10; s[j-1]++; } if(s[j-1]>'9') { s[j-2]++; s[j-1]-=10; } } } // for(i=1;i<) return s; } long long toint(string s) { int k=0; int mn=1; reverse(s.begin(),s.end()); int j=s.size()-1; while(j>=0) { k+=s[j]-48; k*=10; j--; } k/=10; return k; } int main() { int m; m=0; int i,j,k; int niza[10]; vector<int> v; for(i=1; i<=9; i++) { cin>>niza[i]; m+=niza[i]; } for(i=1; i<=9; i++) { for(j=0; j<niza[i]; j++) { v.push_back(i); } } reverse(v.begin(),v.end()); string prv,vtor; prv+=v[0]+48; for(i=1; i<v.size(); i++) { if(prv.size()<vtor.size()) { prv+=v[i]+48; } else if(prv.size()>vtor.size()) { vtor+=v[i]+48; } else { if(prv>vtor) vtor+=v[i]+48; else prv+=v[i]+48; } } long long x=toint(prv); x*=toint(vtor); string s=mn(prv,vtor); bool okej=false; string res; int to; for(i=0;i<gol-1;i++) { if(s[i]!='0') { okej=true; }if(okej) cout<<s[i]; } return 0; }
-- Bujo
Add new attachment
Only authorized users are allowed to upload new attachments.
List of attachments
«
This page (revision-8) was last changed on 20-Aug-2015 17:35 by filip_bujaroski
G’day (anonymous guest)
Log in
JSPWiki v2.8.3