Еве неофицијални решенија:
Коцки:#
C++#
#include<iostream> #include<algorithm> using namespace std; int main() { int m,n,b; cin>>m>>n; b=min(m,n); if(b%2!=0) b--; cout<<b*b; return 0; }
Озборување:#
C++#
#include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> using namespace std; int main() { int m,n,i,j,a,b,max=0,cur; bool mat[101][101]; memset(mat,false,sizeof(mat)); cin>>m>>n; for(i=1;i<=m;i++) mat[i][i]=true; for(i=0;i<n;i++){ cin>>a>>b; for(j=1;j<=m;j++) if(mat[j][a] || mat[j][b]) mat[j][a]=mat[j][b]=true; } for(i=1;i<=m;i++){ cur=0; for(j=1;j<=m;j++) if(mat[j][i]) cur++; if(cur>max) max=cur; } cout<<max-1; return 0; }
Прегледување:#
C++#
#include <iostream> using namespace std; int main() { int n, k, kv=0, minvreme=9999999, minkom=9999999; cin>>n>>k; for(int i=1; i<999999; i++) { for(int j=1; j<i; j++) { kv+=j; } if((n%i==0)&&(kv*k+n/i<minvreme)) { minvreme=kv*k+n/i; } else if ((n%i!=0)&&(kv*k+n/i+1<minvreme)) minvreme=kv*k+n/i+1; //minvreme=kv*k+n%i+n/i; else break; kv=0; minkom=i; } cout<<minkom; return 0; }
Регистрација:#
C++#
#include <iostream> #include <sstream> using namespace std; int main() { stringstream ss; string a, rez, plus; int n, plu=1; cin>>a>>n; rez=a; string users[n]; for(int i=0; i<n; i++) { cin>>users[i]; } for(int i=0; i<n; i++) { if(users[i]==rez) { ss<<plu; ss>>plus; rez=a+plus; ss.str(""); ss.clear(); plu++; i=-1; } } cout<<rez; return 0; }
Одземање:#
C++#
#include <iostream> using namespace std; void bubblesort(string &a) { char tmp; for(int i=0; i<a.length(); i++) { for(int j=0; j<a.length()-1; j++) { if(a[j]>a[j+1]) { tmp=a[j]; a[j]=a[j+1]; a[j+1]=tmp; } } } } void bubblesortrev(string &a) { char tmp; for(int i=0; i<a.length(); i++) { for(int j=0; j<a.length()-1; j++) { if(a[j]<a[j+1]) { tmp=a[j]; a[j]=a[j+1]; a[j+1]=tmp; } } } } int main() { char min='9'; string broj, minbroj; cin>>broj; minbroj=broj; bubblesort(minbroj); bubblesortrev(broj); for(int i=0; i<broj.length(); i++) { if(broj[i]-minbroj[i]+'0'<'0') { for(int j=i-1; j>=0; j--) { if(broj[j]-1>='0') { broj[j]--; break; } else { broj[j]='9'; } } broj[i]=broj[i]-minbroj[i]+'9'+1; } else broj[i]=broj[i]-minbroj[i]+'0'; } int loc=broj.length()-1; for(int i=0; i<broj.length(); i++) { if(broj[i]=='0') continue; else { loc=i; break; } } for(int i=loc; i<broj.length(); i++) { cout<<broj[i]; } return 0; }
Финкимен:#
C++#
#include <iostream> using namespace std; int r, c, minpole=999999, minr, minc; int pole[50][50]; bool check() { for(int i=0; i<r; i++) { for(int j=0; j<c; j++) { if(pole[i][j]!=-1) return false; } } return true; } void findmin() { for(int i=0; i<r; i++) { for(int j=0; j<c; j++) { if((pole[i][j]!=-1)&&(pole[i][j]<minpole)) { minpole=pole[i][j]; minr=i; minc=j; } } } } void fill(int x, int y) { int val=pole[x][y]; pole[x][y]=-1; if((x+1<r)&&(pole[x+1][y]>=val)) fill(x+1, y); if((x-1>=0)&&(pole[x-1][y]>=val)) fill(x-1, y); if((y+1<c)&&(pole[x][y+1]>=val)) fill(x, y+1); if((y-1>=0)&&(pole[x][y-1]>=val)) fill(x, y-1); } int main() { int res=0; cin>>r>>c; for(int i=0; i<r; i++) { for(int j=0; j<c; j++) { cin>>pole[i][j]; if(pole[i][j]<minpole) { minr=i; minc=j; minpole=pole[i][j]; } } } while(check()==false) { fill(minr, minc); res++; minpole=999999; findmin(); } cout<<res; return 0; }
Финкимен co breadth first search(bfs):#
C++#
#include <iostream> #include<queue> using namespace std; int mat[51][51],n,m,iii,jjj,miin=99999,mat2[51][51]={0}; bool check(){ for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mat2[i][j]==0) return false; return true; } void miiin(){ for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mat[i][j]<miin && mat2[i][j]!=1){ miin=mat[i][j]; iii=i; jjj=j; } } int main() { int i,j,I,J,sum=0,pom; cin>>n>>m; queue<int> qi,qj; for(i=0;i<n;i++) for(j=0;j<m;j++) cin>>mat[i][j]; while(!check()){ miiin(); sum++; qi.push(iii); qj.push(jjj); mat2[iii][jjj]=1; while(!qi.empty()){ I=qi.front(); J=qj.front(); qi.pop(); qj.pop(); pom=mat[I][J]; if(mat2[I][J+1]==0 && mat[I][J+1]>=pom && J+1<=m){ //desno qi.push(I); qj.push(J+1); mat2[I][J+1]=1; } if(mat2[I][J-1]==0 && mat[I][J-1]>=pom && J-1>=0){ // levo qi.push(I); qj.push(J-1); mat2[I][J-1]=1; } if(mat2[I+1][J]!=1 && mat[I+1][J]>=pom && I+1<=n){ //dole qi.push(I+1); qj.push(J); mat2[I+1][J]=1; } if(mat2[I-1][J]!=1 && mat[I-1][J]>=pom && I-1>=0){//gore qi.push(I-1); qj.push(J); mat2[I-1][J]=1; } } miin=99999; } cout<<sum; return 0; }
-- Филип Беџовски
Add new attachment
Only authorized users are allowed to upload new attachments.
«
This page (revision-4) was last changed on 20-Aug-2015 17:35 by bedzo
G’day (anonymous guest)
Log in
JSPWiki v2.8.3