luogu 水题记

P2077 红绿灯

#include 

using namespace std;
const int N = 1e5 + 10;

int dis[N];
int n, m;
int r[N];
int g[N];
int answer;

inline int read()
{
    char c=getchar();
    int x=0;
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x;
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n - 1; i ++)
        cin >> dis[i];
    for(int i = 1; i <= n; i ++)
        r[i] = read();
    for(int i = 1; i <= n; i ++)
        g[i] = read();
    answer += m;
    for(int i = 1; i < n; i ++)
    {
        int lgj = answer % (g[i] + r[i]);
        if(lgj > g[i])
            answer += (r[i] + g[i] - lgj);
        printf("%d\n", answer);
        answer += dis[i];
    }
    int lgj = answer % (g[n] + r[n]);
    if(lgj > g[n])
        answer += (r[n] + g[n] - lgj);
        printf("%d\n", answer);
    return 0;
}

 

P1888 三角函数

#include 
#include 
#include 
#include 
#include <string>

using namespace std;

int GCD(int a, int b){
    return b == 0 ? a : GCD(b, a % b);
}

int main(){
    int n, m, b;
    cin >> n >> m >> b;
    int fz = min(min(n, m), b);
    int fm = max(max(n, m), b);
    int gcd = GCD(fz, fm);
    printf("%d/%d", fz / gcd, fm / gcd);
}

P2181 对角线

#include
#include
using namespace std;
unsigned long long n;
int main()
{
    for(int i = 1; i <= -1; i ++) cout << "lgjsb";
    cin>>n;
    cout<<(n*(n-1)/2*(n-2)/3*(n-3)/4)<<endl;
    return 0;
}

P1976 鸡蛋饼

#include
#include
#include

using namespace std;

long long f[100001];

int main()
{
    int n;
    scanf("%d",&n);
    f[0]=1; f[1]=1;
    for(int i=2;i<=n;i++)
        for(int j=1;j<=i;j++)
            f[i]=(f[i]+f[j-1]*f[i-j])%100000007;
    printf("%lld",f[n]);
}

P3150 pb的游戏(1)

#include 

using namespace std;

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        int m;
        cin >> m;
        if(m % 2) printf("zs wins\n");
        else printf("pb wins\n");
    }
    
    
    return 0;
}

P1838 三子棋I

#include
#include
#include
#include<string>
using namespace std;
int vis[4][4];//模拟棋盘
char s[10];//棋谱
int main()
{
    scanf("%s",s+1);//输入字符串
    int len=strlen(s+1);
    int flag=1;
    for(int i=1;i<=len;i++)
    {
        flag=-flag;//每次将flag变成相反数,代表更换执棋者
        if(s[i]=='1')
            vis[1][1]=flag;
        if(s[i]=='2')
            vis[1][2]=flag;
        if(s[i]=='3')
            vis[1][3]=flag;
        if(s[i]=='4')
            vis[2][1]=flag;
        if(s[i]=='5')
            vis[2][2]=flag;
        if(s[i]=='6')
            vis[2][3]=flag;
        if(s[i]=='7')
            vis[3][1]=flag;
        if(s[i]=='8')
            vis[3][2]=flag;
        if(s[i]=='9')
            vis[3][3]=flag;
    }
    if((vis[1][1]==1&&vis[1][2]==1&&vis[1][3]==1)||(vis[2][1]==1&&vis[2][2]==1&&vis[2][3]==1)||(vis[3][1]==1&&vis[3][2]==1&&vis[3][3]==1)||(vis[3][3]==1&&vis[1][1]==1&&vis[2][2]==1)||(vis[3][1]==1&&vis[2][2]==1&&vis[1][3]==1)||(vis[1][1]==1&&vis[2][1]==1&&vis[3][1]==1)||(vis[1][1]==1&&vis[1][2]==1&&vis[1][3]==1)||(vis[1][2]==1&&vis[2][2]==1&&vis[3][2]==1)||(vis[1][3]==1&&vis[2][3]==1&&vis[3][3]==1))//枚举8种情况
        printf("uim wins.");
    else if((vis[1][1]==-1&&vis[1][2]==-1&&vis[1][3]==-1)||(vis[2][1]==-1&&vis[2][2]==-1&&vis[2][3]==-1)||(vis[3][1]==-1&&vis[3][2]==-1&&vis[3][3]==-1)||(vis[3][3]==-1&&vis[1][1]==-1&&vis[2][2]==-1)||(vis[3][1]==-1&&vis[2][2]==-1&&vis[1][3]==-1)||(vis[1][1]==-1&&vis[2][1]==-1&&vis[3][1]==-1)||(vis[1][1]==-1&&vis[1][2]==-1&&vis[1][3]==-1)||(vis[1][2]==-1&&vis[2][2]==-1&&vis[3][2]==-1)||(vis[1][3]==-1&&vis[2][3]==-1&&vis[3][3]==-1))////枚举8种情况
        printf("xiaoa wins.");
    else printf("drew.");
}

P2043 质因子分解

#include
#include
#include
using namespace std;
int sum[10001];
void fenjie(int x);
bool pz(int x);
int main()
{
    int a,b,c,d,e;
    int l,m,n,s,q;
    cin>>n;
    for (a=2;a<=n;a++)
        if (!pz(a)) fenjie(a);
        else sum[a]++;
    for (a=2;a<=n;a++)
        if (sum[a])
            cout<' '<endl;
    return 0;
}
bool pz(int x)
{
    int a,b=sqrt(x)+1;
    for (a=2;a<=b;a++)
        if (x%a==0) return 0;
    return 1;
}
void fenjie(int x)
{
    int a;
    for (a=2;;a++)
    {
        if (x%a==0)
        {
            sum[a]++;
            x/=a;
            a--;
        }
        if (x<=1) break;
    }
}

 P1424 小鱼的航程(改进版)

#include 

#define LL long long

using namespace std;

int main()
{
    LL n, m, answer = 0;
    cin >> n >> m;
    if(n < 6) answer += 5 - n + 1;
    m -= (7 - n + 1);
    answer += (m / 7) * 5;
    if(m % 7 < 6 && m % 7 != 0) answer += m % 7;
    else if(m % 7 != 0 && m % 7 >= 6) answer += 5;
    cout << answer * 250;
    return 0;
}

 P1909 买铅笔

#include 

using namespace std;

struct Node{
    int baoshuliang;
    int baojiage;
    int xvyaomaijibao;
}jiegouti[4];
int yigongxvyaomaijizhi;

int main()
{
    int answer = 999999999;
    cin >> yigongxvyaomaijizhi;
    for(int i = 1; i <= 3; i ++)
    {
        cin >> jiegouti[i].baoshuliang >> jiegouti[i].baojiage;
        jiegouti[i].xvyaomaijibao = yigongxvyaomaijizhi % jiegouti[i].baoshuliang == 0 ? yigongxvyaomaijizhi / jiegouti[i].baoshuliang : yigongxvyaomaijizhi / jiegouti[i].baoshuliang + 1;
        answer = min(answer, jiegouti[i].xvyaomaijibao * jiegouti[i].baojiage);
    }
    printf("%d", answer);
    return 0;
}

P1319 压缩技术

#include 

using namespace std;

int a[40010];

int main()
{
    int n;
    cin >> n;
    int sb;
    int js = 0;
    int how = 0;
    while(scanf("%d", &sb) == 1)
    {
        how ++;
        if(how % 2)//1
        {
            for(int i = js + 1; i <= js + sb; i ++) a[i] = 0;
            js += sb;
        }
        else
        {
            for(int i = js + 1; i <= js + sb; i ++) a[i] = 1;
            js += sb;
        }
    }
    int tot = 0;
    for(int i = 1; i <= n * n; i ++)
    {
        cout<<a[i];
        tot ++;
        if(!(tot % n))
        {
            tot = 0;
            cout << endl;
        }
    }    
    
    return 0;
}

P1320 压缩技术(续集版)

#include 

using namespace std;

string s;

int main()
{
    cin >> s;
    int len = s.length();
    for(int i = 1; i < len; i ++)
    {
        string ss;
        cin >> ss;
        s +=ss;
    }
    cout << len << " ";
    int lenn = len * len;
    if(s[0] != '0') cout << 0 << " ";
    for(int i = 0; i < lenn; i ++)
    {
        int js = 0;
        while(s[i + 1] == s[i]) js ++, i ++;
        cout << js + 1 << " ";
    }
    return 0;
}

P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm

#include
using namespace std;
long long ans,sum;
long long n,k;
void dfs(int x)
{
    if(x-k<=0) {
    sum++;return;//这条路走到头了,结果++
    }
    if((x+k)%2==0)
    {
    dfs((x+k)/2);
    dfs(x-(x+k)/2);//继续走,分两半递归
    }
    else sum++;
}
int main()
{
    cin>>n>>k;
    dfs(n);
    cout<<sum;
}

P1496 火烧赤壁

#include
#include
#include

#define maxn 20010

using namespace std;

int n;
int xx, yy, answer;

struct node {
    int x, y;
} a[maxn];

struct Node {
    inline int read() {
        int x = 0, f = 1;
        char c = getchar();
        while(c < '0' || c > '9') {
            if(c == '-') f = -1;
            c = getchar();
        }
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
}r;

int cmp(node u, node v) {
    return u.x < v.x;
}

int main() {
    n = r.read();
    for(int i = 1; i <= n; i ++) a[i].x = r.read(), a[i].y = r.read();
    
    sort(a + 1, a + n + 1, cmp);
    xx = a[1].x;
    yy = a[1].y;
    answer += a[1].y - a[1].x;
    for(int i = 2; i <= n; i ++) 
    {
        if(a[i].x <= yy) 
        {
            if(a[i].y < yy) continue;
            else 
            {
                xx = yy;
                yy = a[i].y;
                answer += yy - xx;
            }
        }
        if(a[i].x > yy) 
        {
            xx = a[i].x;
            yy = a[i].y;
            answer += yy - xx;
        }
    }
    printf("%d", answer);
    return 0;
}

 P1789 【Mc生存】插火把

#include 

using namespace std;
const int N = 1000;

int n, m, k;
bool a[N][N];

inline int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int main()
{
    n = read();
    m = read();
    k = read();
    for(int i = 1; i <= m; i ++)
    {
        int x = read();
        int y = read();
        x += 2;
        y += 2;
        a[x][y] = a[x][y - 1] = a[x][y - 2] = a[x - 1][y] = a[x - 2][y] = a[x][y + 1] = a[x][y + 2] = a[x + 1][y] = a[x + 2][y] = 1;
        a[x - 1][y - 1] = a[x - 1][y + 1] = a[x + 1][y - 1] = a[x + 1][y + 1] = 1; 
    }
    for(int i = 1; i <= k; i ++)
    {
        int x = read();
        int y = read();
        for(int l = x; l <= x + 4; l ++)
            for(int r = y; r <= y + 4; r ++)
                a[l][r] = 1;
    }
    int answer = 0;
    for(int i = 3; i <= n + 2; i ++)
        for(int j = 3; j <= n + 2; j ++)
            if(!a[i][j]) answer ++;
    printf("%d", answer);
    
    return 0;
}

 P1138 第k小整数

#include 

int n, k;
bool tong[300001];

inline int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int main()
{
    n = read();
    k = read();
    for(int i = 1; i <= n; i ++)
        tong[read()] = 1;
    int js = 0;
    for(int i = 0; i <= 300000; i ++)
    {
        if(tong[i]) js ++;
        if(js == k)
        {
            printf("%d", i);
            return 0;
        } 
    }
    printf("NO RESULT");
    return 0;
}

 P2550 [AHOI2001]彩票摇奖

#include 

bool tong[40];
int jl[8];

inline int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int main()
{
    int n = read();
    for(int i = 1; i <= 7; i ++)
        tong[read()] = 1;
    for(int i = 1; i <= n; i ++)
    {
        int js = 0;
        for(int j = 1; j <= 7; j ++) if(tong[read()]) js ++;
        jl[7 - js] ++;
    }
    for(int i = 0; i < 7; i ++)
        printf("%d ", jl[i]);
    return 0;
}

 P1597 语句解析

#include 

using namespace std;

string ss;
char s[250];

int main()
{
    int a = 0, b = 0, c = 0;
    cin >> ss;
    int len = ss.length();
    for(int i = 0; i < len; i ++) s[i + 1] = ss[i];
    for(int i = 1; i <= len; i += 5)
    {
        if(s[i] >= 'a' && s[i] <= 'z' && s[i + 3] >= '0' && s[i + 3] <= '9')//zi mu shu zi
        {
            if(s[i] == 'a') a = s[i + 3] - '0';
            if(s[i] == 'b') b = s[i + 3] - '0';
            if(s[i] == 'c') c = s[i + 3] - '0';
        }
        else
        {
            if(s[i] == 'a' && s[i + 3] == 'b') a = b;
            if(s[i] == 'a' && s[i + 3] == 'c') a = c;
            if(s[i] == 'b' && s[i + 3] == 'a') b = a;
            if(s[i] == 'b' && s[i + 3] == 'c') b = c;
            if(s[i] == 'c' && s[i + 3] == 'a') c = a;
            if(s[i] == 'c' && s[i + 3] == 'b') c = b;
        }
    }
    printf("%d %d %d", a, b, c);
    
    
    return 0;
}

 P1847 轰炸II

#include 


using namespace std;
const int N = 2e3 + 10;

int m, n;
struct Node{
    int x, y, xx, yy;
}E[N];
struct node{
    int x, y, js, last;
}Z[N];

inline int read()
{
    char c=getchar();
    int x=0;
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x;
}

int main()
{
    m = read();
    n = read();
    for(int i = 1; i <= m; i ++)
    {
        E[i].x = read();
        E[i].y = read();
        E[i].xx = read();
        E[i].yy = read();    
    }
    for(int i = 1; i <= n; i ++)
    {
        Z[i].x = read();
        Z[i].y = read();
    }
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            if(Z[i].x >= E[j].x && Z[i].x <= E[j].xx && Z[i].y >= E[j].y && Z[i].y <= E[j].yy)
                Z[i].js ++, Z[i].last = j;
        }
    }
    for(int i = 1; i <= n; i ++)
    {
        if(!Z[i].js) printf("NO\n");
        else printf("YES %d %d\n", Z[i].js, Z[i].last);
    }
    return 0;
}

P1590 失踪的7

#include 

using namespace std;

int main()
{
    int n; 
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        long long a;
        cin >> a;
        int answer = a;
        for(int j = 1; j <= a; j ++)
        {
            int tmp = j;
            bool flag = 1;
            while(tmp && flag)
            {
                if(tmp % 10 == 7)
                {
                    answer --;
                    flag = 0;
                }
                tmp /= 10;
            }
        }
        printf("%lld\n", answer);
    }
    
    
    return 0;
}

 P1936 水晶灯火灵

#include
using namespace std;
long long f[1001],m,i(3);
int main(){
    cin>>m;
    f[1]=1;f[2]=1;//赋值前两个
    while(f[i]+f[i-1]<=m){
        f[i]=f[i-1]+f[i-2];//将斐波那契数列存储到f数组里
        i++;
    }
    cout<<"m="<3]<//这个地方i多加了一次
    cout<<"n="<2];
    return 0;
//perfect!
}

 

P3741 honoka的键盘

#include 

using namespace std;

int n;
char a[110];
int answer;

int main()
{
    bool flag = 1;
    cin >> n;
    scanf("%s", a + 1);
    for(int i = 1; i < n; i ++)
        if(a[i] == 'V' && a[i + 1] == 'K') answer ++, a[i] = a[i + 1] = '#';
    for(int i = 2; i < n && flag; i ++)
    {
        if(a[i] == 'V' && a[i + 1] != '#') answer ++, flag = 0;
        else if(a[i] =='K' && a[i - 1] != '#') answer ++, flag = 0;
    }
    printf("%d", answer);
    
    return 0;
}

P2911 [USACO08OCT]牛骨头Bovine Bones

#include 

using namespace std;

int s1, s2, s3;
struct Node{
    int js, who;
}a[1000000];

bool cmp(Node aa, Node b)
{
    if(aa.js == b.js) return aa.who < b.who;
    return aa.js > b.js;
}

int main()
{
    cin >> s1 >> s2 >> s3;
    for(int i = 1; i <= s1; i ++)
        for(int j = 1; j <= s2; j ++)
            for(int k = 1; k <= s3; k ++)
                a[i + j + k].js ++, a[i + j + k].who = i + j + k;
    sort(a + 1, a + s1 * s2 * s3 + 1, cmp);
    printf("%d",a[1].who);
    return 0;
}

 P1765 手机_NOI导刊2010普及(10)

#include 

using namespace std;

char c[250];
int js;

int ans[] = {1, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4, 0};

int main()
{
    int answer = 0;
    char ch;
    js = 0;
    while((ch = getchar()) != '\n')
        c[++ js] = ch;
    for(int i = 1; i <= js; i ++)
        if(c[i] == ' ') answer += ans[0];
        else answer += ans[c[i] - 'a' + 1];
    printf("%d", answer);
        
    return 0;
}

 P1482 Cantor表(升级版)

#include 

using namespace std;

inline int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    int xx, yy, aa, bb;
    xx = read();
    yy = read();
    aa = read();
    bb = read();
    int xy = gcd(xx, yy);
    xx /= xy; yy /= xy;
    int ab = gcd(aa, bb);
    aa /= ab; bb /= ab;
    int fz = xx * aa;
    int fm = yy * bb;
    int f = gcd(fz, fm);
    fz /= f; fm /= f;
    printf("%d %d", fm, fz);
    return 0;
}

P2369 EXCEEDED WARNING A

#include 

using namespace std;
const int N = 1e6 + 10;

#define LL long long

int n, m;
LL a[N];

inline LL read()
{
    char c=getchar();
    LL x=0;
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x;
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i ++) a[i] = read();
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= m; i ++) printf("%d\n", a[i]);
    
    return 0;
}

P3879 [TJOI2010]阅读理解

#include 

using namespace std;

map <string, bool> mp[110];

inline int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c  =getchar();
    return x;
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i ++)
    {
        int l; 
        cin>>l;
        for(int j = 1; j <= l; j ++)
        {
            string ls;
            cin >> ls;
            mp[i][ls] = 1;
        }
    }
    int m;
    cin>>m;
    for(int i = 1; i <= m; i ++)
    {
        string s;
        cin >> s;
        for(int j = 1; j <= n; j ++)
            if(mp[j][s])
            {
                printf("%d ", j); 
                continue ;    
            }
        printf("\n");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/lyqlyq/p/7741101.html

你可能感兴趣的:(luogu 水题记)