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;
}