Еве неофицијални решенија:

Броеви:#

C++#

#include <iostream>
using namespace std;

int main()
{
    int broj[25],i,j,n,m,pom1,pom2,z=0,sum=0,la;
    cin>>n>>m;
    for(i=n;i<m+1;i++){
        z=0;
        la=i;
    while(la>=10){
    pom1=la%10;
    pom2=(la/10)%10;
    la/=10;
    if(pom1<=pom2){
    z++;
    break;
    }
    }
    if(z==0) sum++;
    }
    cout<<sum;
    return 0;
}

Згради:#

C++#

#include <iostream>
#include<vector>
#include<cstring>
using namespace std;

int main()
{
    int n,zgradi[600],max=0,sum=0,i;
    cin>>n;
    for(i=0;i<n;i++) cin>>zgradi[i];
    for(i=0;i<n;i++) if(zgradi[i]>max) max=zgradi[i];
    for(i=0;i<n;i++) sum+=max-zgradi[i];
    cout<<sum;
    return 0;
}

Зборови:#

C++#

#include <iostream>
#include<vector>
#include<string>
using namespace std;
char buk[100];
int vred[100];

int main()
{
    int i,n,j,m,sum=0,max=0,h;
    string f,mm;
    for(i=0;i<26;i++) cin>>buk[i]>>vred[i];
    cin>>m;
    for(i=0;i<26;i++){
        for(j=i+1;j<26;j++){
    if(buk[j]<buk[i]){
    swap(buk[j],buk[i]);
    swap(vred[j],vred[i]);
    }
    }
    }
    for(i=0;i<26;i++){
    buk[i+26]=buk[i]-32;
    vred[i+26]=vred[i]+20;
    }
    for(i=0;i<m;i++){
    cin>>f;
    sum=0;
    for(h=0;h<f.size();h++){
    for(j=0;j<52;j++){
    if(f[h]==buk[j]) sum+=vred[j];
    }
    }
    if(sum>max){
    max=sum;
    mm=f;
    }
    }
    cout<<mm;
    return 0;
}

Е-пораки:#

C++#

#include <iostream>

using namespace std;
int a[10000],b[10000];
int main()
{
    int i,j,z,x,m,n,f;
    cin>>m>>n;
    f=n;
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(i=0;i<n;i++)
    {
        z=a[i];
        x=b[i];
        for(j=i+1;j<n;j++)
        {
            if(a[j]==x && b[j]==z) f-=2;
        }
    }
    cout<<f;
    return 0;
}

Експанзија:#

C++#

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
	char izl[400],chr[1];
	string vl;
	int i=0,m,k=0;

	cin >> vl;
	
	for (i=0; i<vl.length(); i++)
	{
		chr[0] = vl[i];
		m = atoi(chr);
		if (m>0 && m<10)
		{
			for (int j=k; j<m+k; j++)
				izl[j]=vl[i+1];
			k+=m-1;
		}
		else
		{
			izl[k]=vl[i];
			k++;
		}
	}

	for (i=0; i<k; i++)
		cout << izl[i];

	return 0;
}

Поплава:#

C++#

#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int r[51][2],najg=0,n,i,j;
    long long rab,sum=0;
    cin>>n;
    r[0][0]=0;
    r[0][1]=0;

    for(i=1;i<=n;i++)
    {
        cin>>r[i][0]>>r[i][1];
        sum+=r[i][0];
    }
    for(i=1;i<n+1;i++)
    {
        for(j=i+1;j<n+1;j++)
        {
            if(r[j][1]<r[i][1])
            {
                swap(r[j][1],r[i][1]);
                swap(r[j][0],r[i][0]);
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        sum-=r[i-1][0];
        rab=sum*r[i][1];
        if(rab>najg) najg=rab;
    }
    cout<<najg;

    return 0;
}

ТВ одмор:#

C++#

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    
    vector<int> starts, ends;
    
    for (int i=0; i<n; i++)
    {
        int shh, smm, ehh, emm;
        cin >> shh >> smm >> ehh >> emm;
                                
        starts.push_back(shh*60 + smm);
        ends.push_back(ehh*60 + emm);
        
        if (ends[i] <= starts[i])
           ends[i] += 24*60;
    }

	int dp[205][205];
	int nshows = starts.size();

	for (int i=0; i<nshows; i++)
		starts.push_back(starts[i]+24*60); 

	for (int i=0; i<nshows; i++)
		ends.push_back(ends[i]+24*60);

	//initialize dp
	for (int i=0; i<205; i++)
		 for (int j=0; j<205; j++)
			 dp[i][j] = 0;

	for (int i=0; i<starts.size(); i++)
	   for (int j=0; j<starts.size(); j++)
		  if(ends[i]<=starts[j]) 
			 dp[i][j]=ends[i]-starts[i];

	for (int j=0; j<starts.size(); j++)
	  for (int i=0; i<starts.size(); i++)
		 for (int k=0; k<starts.size(); k++)
			  if(dp[i][j] && dp[j][k]) 
				 dp[i][k]=max(dp[i][k], dp[i][j]+dp[j][k]);

	int result=0;
	for (int i=0; i<starts.size()/2; i++)
		result=max(result, dp[i][i+starts.size()/2]);
 
	cout << result << endl;    
    return 0;
}

Државна резерва:#

C++#

#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    int a[1001][2],i,j,n,m,sum=0;
    cin>>n>>m;
    for(i=0;i<m;i++) cin>>a[i][0]>>a[i][1];
    for(i=0;i<m;i++){
    for(j=i+1;j<m;j++){
    if(a[j][0]<a[i][0]){
    swap(a[j][1],a[i][1]);
    swap(a[j][0],a[i][0]);
    }
    }
    }
    i=0;
    while(n>0){
    if(a[i][1]>n){
    sum+=a[i][0]*n;
    n=0;
    }
    else{
    sum+=a[i][0]*a[i][1];
    n-=a[i][1];
    }
    i++;
    }
    cout<<sum;
    return 0;
}

Затвор:#

C++#

#include <iostream>
#include <queue>
#include <fstream>
#include <cstring>

using namespace std;

int di[]={-1,1,0,0};
int dj[]={0,0,-1,1};
char mat[1001][1001]; 
int dist[1001][1001];
bool vis[1001][1001];
vector <int> guards;
int n,m,si,sj,ei,ej;


class field
{
  public:
  field(){}
  field(int I,int J,int D) {i=I; j=J; d=D;}
  int i,j,d;
};

bool operator <(const field &a ,const field &b)
{
  return a.d<b.d;
}

void fill1()
{
  queue<int> q;
  int i,j,k;

  i=0;
  memset(dist,-1,sizeof(dist));
  while(i<guards.size())
  {
    q.push(guards[i]);
    q.push(guards[i+1]);
    dist[guards[i]][guards[i+1]]=0;
    i+=2;
  }

int gi,gj;
int ni,nj;
  while(!q.empty())
  {
    gi=q.front();
    q.pop();
    gj=q.front();
    q.pop();

    for(k=0;k<4;k++)
    {
      ni=gi+di[k];
      nj=gj+dj[k];

      if(ni>=0 && ni<n && nj>=0 && nj<m && 
         mat[ni][nj]!='*' && dist[ni][nj]==-1) 
      {
         dist[ni][nj]=dist[gi][gj]+1;
         q.push(ni);
         q.push(nj);
      }
    }
  }
}

int fill2()
{
  int res=10000000;
  priority_queue<field> q;
  memset(vis,false,sizeof(vis));
  field tmp;
  int ni,nj,k;
  q.push( field(si,sj,dist[si][sj]) );
vis[si][sj]=true;
  while(!q.empty())
  {
    tmp=q.top();
    q.pop();
    if(tmp.i==ei && tmp.j==ej)
    {
      //if(tmp.d<res) res=tmp.d;
      return tmp.d;
    }
    for(k=0;k<4;k++)
    {
      ni=tmp.i+di[k];
      nj=tmp.j+dj[k];
      if(ni>=0  && ni<n && nj>=0 && nj<m &&
         mat[ni][nj]!='*' && !vis[ni][nj])
      {
         q.push(field(ni,nj,min(tmp.d,dist[ni][nj])));
         vis[ni][nj]=true;
      }
    }
  }
  return res;
}
void locate()
{
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {
       if(mat[i][j]=='R')
       {
            si=i; sj=j;
       }
       if(mat[i][j]=='Z')
       {
            ei=i; ej=j;
       }
       if(mat[i][j]=='G')
       {
          guards.push_back(i);
          guards.push_back(j);
       }
    }
}
int main()
{
    int i,j;
    cin>>n>>m;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>mat[i][j];
   locate();
   fill1();
   cout<<fill2();

    return 0;
}




Решенијата за ТВ одмор и Затвор ги превземав од форумот.

--Филип Беџовски

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-3) was last changed on 20-Aug-2015 17:35 by bedzo