2016蓝桥杯C/C++省赛 凑算式+搭积木(暴力,水题)

来源:互联网 发布:js时间戳与php时间戳 编辑:程序博客网 时间:2024/05/17 00:52

题目:


代码:(答案是29种)

#include <stdio.h>#include <string.h>#include <string>#include <iostream>#include <stack>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define N 1000+10#define LL long longusing namespace std;int main(){    double cnt=0;    for(double a=1; a<=9; a++)    for(double b=1; b<=9; b++)    for(double c=1; c<=9; c++)    for(double d=1; d<=9; d++)    for(double e=1; e<=9; e++)    for(double f=1; f<=9; f++)    for(double g=1; g<=9; g++)    for(double h=1; h<=9; h++)    for(double i=1; i<=9; i++)    if((a!=b&&a!=c&&a!=d&&a!=e&&a!=f&&a!=g&&a!=h&&a!=i)     &&(b!=a&&b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h&&b!=i)     &&(c!=b&&c!=a&&c!=d&&c!=e&&c!=f&&c!=g&&c!=h&&c!=i)     &&(d!=b&&d!=c&&d!=a&&d!=e&&d!=f&&d!=g&&d!=h&&d!=i)     &&(e!=b&&e!=c&&e!=d&&e!=a&&e!=f&&e!=g&&e!=h&&e!=i)     &&(f!=b&&f!=c&&f!=d&&f!=e&&f!=a&&f!=g&&f!=h&&f!=i)     &&(g!=b&&g!=c&&g!=d&&g!=e&&g!=f&&g!=a&&g!=h&&g!=i)     &&(h!=b&&h!=c&&h!=d&&h!=e&&h!=f&&h!=g&&h!=a&&h!=i)     &&(i!=b&&i!=c&&i!=d&&i!=e&&i!=f&&i!=g&&i!=h&&i!=a))    // if(b%c==0&&(d*100+e*10+f)%(g*100+h*10+i)==0)     if(a+(b/c)+((d*100+e*10+f)/(g*100+h*10+i))==10)        cnt++;    cout<<cnt<<endl;    return 0;}

题目:



代码(答案是768种):

#include <stdio.h>#include <string.h>#include <string>#include <iostream>#include <stack>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define N 1000+10#define LL long longusing namespace std;int main(){    int cnt=0;    for(int a=0; a<=9; a++)    for(int b=0; b<=9; b++)    for(int c=0; c<=9; c++)    for(int d=0; d<=9; d++)    for(int e=0; e<=9; e++)    for(int f=0; f<=9; f++)    for(int g=0; g<=9; g++)    for(int h=0; h<=9; h++)    for(int i=0; i<=9; i++)    for(int j=0; j<=9; j++)    if((a!=b&&a!=c&&a!=d&&a!=e&&a!=f&&a!=g&&a!=h&&a!=i&&a!=j)     &&(b!=a&&b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h&&b!=i&&b!=j)     &&(c!=b&&c!=a&&c!=d&&c!=e&&c!=f&&c!=g&&c!=h&&c!=i&&c!=j)     &&(d!=b&&d!=c&&d!=a&&d!=e&&d!=f&&d!=g&&d!=h&&d!=i&&d!=j)     &&(e!=b&&e!=c&&e!=d&&e!=a&&e!=f&&e!=g&&e!=h&&e!=i&&e!=j)     &&(f!=b&&f!=c&&f!=d&&f!=e&&f!=a&&f!=g&&f!=h&&f!=i&&f!=j)     &&(g!=b&&g!=c&&g!=d&&g!=e&&g!=f&&g!=a&&g!=h&&g!=i&&g!=j)     &&(h!=b&&h!=c&&h!=d&&h!=e&&h!=f&&h!=g&&h!=a&&h!=i&&h!=j)     &&(i!=b&&i!=c&&i!=d&&i!=e&&i!=f&&i!=g&&i!=h&&i!=a&&i!=j)     &&(j!=b&&j!=c&&j!=d&&j!=e&&j!=f&&j!=g&&j!=h&&j!=i&&j!=a))     if(d<g&&d<h&&e<h&&e<i&&f<i&&f<j&&b<d&&b<e&&c<e&&c<f&&a<b&&a<c)        cnt++;    cout<<cnt<<endl;    return 0;}
这两道题。。好水啊,好暴力啊。。写出的代码好羞耻。。第二大道题竟然跑了45秒。。。尴尬,别骂我,能出来答案就好

0 0
原创粉丝点击