一:Find Amir 二:Iroha Loves Strings 三: Iroha's Obsession

Find Amir:链接
题目大意:有n所学校,需要每所学校都走一遍,每两所学校之间的车票费为(i+j)%(n+1)  ,学校的起始点与终止点任意,问怎样选择,使车费最低
思路:每次都是选择最靠前的与最靠后的,假设有10所学校,(1+10)%11=0   (2+9)%11=0   以此类推共五组,把这五组接起来,车费为4.例如从10到9  (10+9)%11=1   依次类推共四组

代码:
 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
       int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n%2==0) cout<<n/2-1<<endl;
          else cout<<(n-1)/2-1+(((n+1)/2)+((n+1)/2+1))%(n+1)<<endl;
    }
    return 0;
}
题解中有的不分学校为奇偶数,直接输出(n-1)/2

Iroha Loves Strings:链接
题目大意:给N个串,每串长度为L,将这n个串按最小字典序连接起来
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,l;
    while(cin>>n>>l)
    {
        string s[105];
        int a[105];
        for(int i = 0 ; i < n ; i++ )
            cin>>s[i];
        sort(s+0,s+n);
       /* for(int i=0;i<n;i++)
             cout<<s[i]<<endl;*/
        for(int j = 0;j < n;j++ )
            cout<<s[j];
        cout<<endl;

    }
    return 0;
}

 Iroha's Obsession:链接
题目大意:给一个n,一个k,n代表现在拥有的钱的数目,k代表不喜欢的k个数字,输出k个数。问拥有的钱数中不包含这k个数字,最少的钱应是多少。
思路:以现在拥有的钱为底数,一次向上累加,直到其中不包含自己不喜欢的数字
代码:
 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int vis[11];
int check(int n)
{
	while(n)
	{
		if(vis[n%10]==1)
			return 0;
		n/=10;
	}
	return 1;
}
int main()
{
	int n,k;
	int x;
	scanf("%d%d",&n,&k);

        for(int i=0;i<k;i++)
	    {
		   cin>>x;
		   vis[x]=1;
	    }
	    for(int i=n;i>0;i++)
	    {
		   if(check(i))
		   {
                       cout<<i<<endl;
                        return 0;

                   }
	    }


	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值