题目来源各处都有,难度都是水题难度,但是又不是单纯模拟,有点意思的

No.1

牛客练习赛29A

思路:所有的正数都从1号位置出,所有的负数都不变,倒着来从自己的位置出去。

代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=1e6+7;
const int INF=0x3f3f3f3f;
typedef long long ll;
ll a[maxn];
int T;
ll sum,x;
int main(){
    scanf("%d",&T);
    for(int i=1;i<=T;i++){
        scanf("%lld",&a[i]);
        if(a[i]>=0)
        sum+=a[i];
    }
    for(int i=T;i>=0;i--){
        if(a[i]<0)sum+=(a[i]*i);
    }
    printf("%lld\n",sum);
    return 0;
}

No.2

其实这道题,没多少意思,算是比较水的了,但是勉强加上吧

相邻的数本来就互质。。。。所以数数这个环有几对数就好了,n个数围成环有n对数。输入n输出n。

No.3

链接:https://www.nowcoder.com/acm/contest/204/D

思路:是个完全图,那就是所有点和其他任意点都有边,那最小的权值之和,就是值最小的那个点,和值最小的2--n个点连成的最小生成树,排序后a0*(n-1)+    a1-----a(n-1)累加

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int n;
int a[maxn];
int main(){
    scanf("%d",&n);
    ll ans=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=1;i<n;i++){
        ans+=a[i];
    }
    ans+=((n-1)*a[0]);
    printf("%lld",ans);
    return 0;
}

No.4

题目描述

“自选”在工大还是挺受欢迎的,在某自选餐厅,有菜品 <  s  < 7 种, 主食 1 < h < 4 种, 饮料 1 < z < 3 种, 请问在这家餐厅你有几种选择的方法,注意:一种食物不论你买了多少,无差别,而且你不在这家餐厅吃饭也是一种合法的挑选方法。

例如:餐厅中如果只有 1 种菜品,1 种主食,1 种饮料,你的选择方法如下:000,001,010, 011,100,101,110, 111。一共八种选择。

输入

第一行一个正整数N(0 < N <= 36)。
接下来 N 行数据,每行三个正整数 s, h, z (以空格隔开,且1 <  s  < 7 ,  1 < h < 4 , 1 < z < 3 )。

输出

对每行输入,输出其对应总挑选的方法,单独占一行。

样例输入

2
1 1 1
1 2 2

样例输出

8
32

n种不同的物品从中拿,可以拿0种,也可以拿1种,2种,,,,n种。情况共有2^n(2的n次方)

代码

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
int T,a,b,c;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d",&a,&b,&c);
        int sum1=1;
        for(int i=1;i<=a;i++)sum1*=2;
        int sum2=1;
        for(int i=1;i<=b;i++)sum2*=2;
        int sum3=1;
        for(int i=1;i<=c;i++)sum3*=2;
        printf("%d\n",sum1*sum2*sum3);
    }
    return 0;
}

No.5

51nod1347 旋转字符串

题目读懂了 其实就很简单   很容易发现:对串无论怎样旋转都还是对串

所以 这个题就是判断有没有对串的问题

代码

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e6+7;
char str[maxn];
int main(){
    scanf("%s",str);
    int l=strlen(str);
    if(l%2==1){
        printf("NO");return 0;
    }
    int flag=0;
    for(int i=0,j=l/2;i<l/2&&j<l;i++,j++){
        if(str[i]!=str[j]){flag=1;break;}
    }
    if(flag==1)printf("NO");
    else printf("YES");
    return 0;
}