Summer training #7

B:读懂题意模拟

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
int main()
{
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
 int n;
 int m1,m2,y1,y2;
 cin >> n;
 double ans;
 while(n--)
 {
   scanf("%d %d %d %d",&m1,&y1,&m2,&y2);
   //cout<< a << b << c << d<<endl;
   if(y1==y2)
        ans=(m2-m1)/2.0/(13-m1)+EPS;
   else
        ans=0.5+(y2-y1-1)+1.0/12*(m2-1)+EPS;
   printf("%.4lf\n",ans);
 }
  return 0;
}

C:给你一个起点和终点 每个点有补给但是只能拿一次 每条路有经过的cost 问你能不能到终点 能的话最少cost多少 DFS + 剪枝

(对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝.)

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
map<string, int> pos;
struct Edge {
    int v, c, next;
} edge[3000];
int head[3000], cnt;
int vis[3000], amm[3000], aim[3000],sum[3000];
int cs, n, m, ans;
string s, t;

void addedge (int u, int v, int c) {
    edge[++cnt].v = v, edge[cnt].c = c;
    edge[cnt].next = head[u];
    head[u] = cnt;
}
void dfs (int x, int s, int k) {
    if(k>=ans) return;
    if (aim[x]) {
        ans = min (ans, k);
        return ;
    }
    if (!vis[x]) s += amm[x], vis[x] = 1;
    if(vis[x]&&sum[x]>=s) return;
    sum[x]=max(sum[x],s);
    for (int i = head[x]; i; i = edge[i].next) {
        int v = edge[i].v, c = edge[i].c;
        if (s >= c)  dfs (v, s - c, k + c);
    }
    vis[x] = 0;
}
int main() {
    scanf ("%d", &cs);
    while (cs--) {
        pos.clear();
        memset (head, 0, sizeof head);
        memset(sum,0,sizeof sum);
        memset(vis,0,sizeof vis);
        cnt = 1, ans = 0x7fffffff;
        scanf ("%d %d", &n, &m);
        for (int i = 1; i <= n; i++) {
            cin >> s;
            pos[s] = i;
            cin >> amm[i] >> s;
            if (s[0] == ‘y‘) aim[i] = 1;
            else aim[i] = 0;
        }
        for (int i = 1, x; i <= m; i++) {
            cin >> s >> t >> x;
            int u = pos[s], v = pos[t];
            addedge (u, v, x);
            addedge (v, u, x);
        }
        dfs (1, 0, 0);
        if (ans != 0x7fffffff) printf ("%d\n", ans);
        else puts ("No safe path");
    }
}

D

E:如果有 就先去掉特殊的两个 然后DFS

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
int num[10];
int flag=0;
void dfs(int number)
{
 if(number==4||flag==1)
 {
   flag=1;
   return ;
 }
 for(int i=1;i<=7;i++)
 {
        if(num[i]>=1&&num[i+1]>=1&&num[i+2]>=1)
        {
        num[i]-=1;
        num[i+1]-=1;
        num[i+2]-=1;
        dfs(number+1);
        num[i]+=1;
        num[i+1]+=1;
        num[i+2]+=1;
        }
 }
 for(int i=1;i<=9;i++)
 {
        if(num[i]>=3)
        {
        num[i]-=3;
        dfs(number+1);
        num[i]+=3;
        }
 }
}
void init()
{
        for(int i=1;i<=9;i++)
        {
        if(num[i]<2)
        continue;
        num[i]-=2;
        dfs(0);
        num[i]+=2;
        if(flag==1)
        break;
        }
}
int main()
{
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
 int n;
 cin >> n;
 while(n--)
 {
        flag=0;
        mem(num,0);
        int a[20];
        for(int i=1;i<=14;i++)
        {
        scanf("%d",&a[i]);
        num[a[i]]++;
        }
        init();
       if(flag==1)
        printf("Vulnerable\n");
       else
        printf("Immune\n");
 }
  return 0;
}

F:BFS 注意!!一次outbreak只能在BFS中的每个点发生一次

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
char s[110][110];
char visit[110][110];
queue<pair<int,int> > que;
int dir[4][2];
int n,m;
void bfs()
{
 for(int i=0;i<=101;i++)
 mem(visit[i],0);
 pair<int,int> a;
 while(!que.empty())
 {
        a=que.front();
        que.pop();
        int r=a.first;
        int c=a.second;
        if(s[r][c]==‘D‘)
        {
        for(int i=0;i<4;i++)
        {
        int r1=r+dir[i][0];
        int c1=c+dir[i][1];
        if(r1>=0&&r1<n&&c1>=0&&c1<m&&s[r1][c1]!=‘X‘)
        {
        if(s[r1][c1]==‘D‘&&!visit[r1][c1])
        {
        pair<int,int> b;
        b.first=r1,b.second=c1;
        que.push(b);
        visit[r1][c1]=1;
        }
        else if(s[r1][c1]>=‘A‘&&s[r1][c1]<‘D‘)
        {
        s[r1][c1]=s[r1][c1]+1;
        }
        }
        }
        visit[r][c]=1;
        }
        else if(s[r][c]>=‘A‘&&s[r][c]<‘D‘)
        {
        s[r][c]=s[r][c]+1;
        }
 }
}
int main()
{
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
dir[0][0]=-1,dir[0][1]=0;
dir[1][0]=1,dir[1][1]=0;
dir[2][0]=0,dir[2][1]=1;
dir[3][0]=0,dir[3][1]=-1;
 int t;
 cin >> t;
 while(t--)
 {
        for(int i=0;i<=101;i++)
        mem(visit[i],0);
        int r,c;
        scanf("%d %d",&m,&n);
        for(int i=0;i<n;i++)
        scanf("%s",s[i]);
        int time;
        scanf("%d",&time);
        while(time--)
        {
        scanf("%d %d",&c,&r);
        pair<int,int> a;
        a.first=r,a.second=c;
        que.push(a);
        bfs();
        /*for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                printf("%c",s[i][j]);
                printf("\n");
        }
        cout<<endl;*/
        }
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<m;j++)
                printf("%c",s[i][j]);
                printf("\n");
        }
 }
  return 0;
}

G:水

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
int a[25];
int main()
{
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
 int n;
 cin >> n;
 while(n--)
 {
        for(int i=0;i<20;i++)
                cin>>a[i];
        for(int i=19;i>0;i--)
        {
        if(i!=0)
        a[i-1]+=a[i]/2;
        a[i]=a[i]%2;
        }
        cout<<a[0];
        for(int i=1;i<20;i++)
        cout<<" "<<a[i];
        cout<<endl;
 }
  return 0;
}

F:以分号为界 每个一行 按照题意输出 substr的应用

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
string a,b;
int now=0;
int pop=0;
void doit()
{
 int cur=0;
 string ans;
 for(int i=0;i<b.size();i++)
 {
        if(b[i]==‘;‘)
        {
        ans=b.substr(cur,i-cur+1);
        if(pop==0)
        printf("%d: ",now-1);
        else
        printf("%d: ",now);
        cout<<ans<<endl;
        cur=i+1;
        }
 }
 b=b.substr(cur,b.size()-cur+1);
}
int main()
{
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
  int t;
  cin >> t;
        now=0;
        b=a="";
        while(getline(cin,a))
        {
        now++;
        if(a=="END OF CASE")
        {
        pop=1;
        now=0;
        b="";
        continue;
        }
        b+=a;
        doit();
        }
  return 0;
}

J:

时间: 2024-10-25 08:39:17

Summer training #7的相关文章

Android官方开发文档Training系列课程中文版:手势处理之滚动动画及Scroller

原文地址:http://android.xsoftlab.net/training/gestures/scroll.html 在Android中,滑动经常由ScrollView类来实现.任何超出容器边界的布局都应该将自己内嵌在ScrollView中,以便提供可滚动的视图效果.自定义滚动只有在特定的场景下才会被用到.这节课将会描述这样一种场景:使用scroller显示一种可滚动的效果. 你可以使用Scroller或者OverScroller来收集一些滑动动画所需要的数据.这两个类很相似,但是Ove

2017 UESTC Training for Data Structures

2017 UESTC Training for Data Structures A    水,找区间极差,RMQ怼上去. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,a) for (int i=b;i&

WeChall_Training: Programming 1 (Training, Coding)

When you visit this link you receive a message.Submit the same message back to http://www.wechall.net/challenge/training/programming1/index.php?answer=the_messageYour timelimit is 1.337 seconds 解题: 先在浏览器获取自己的cookie,再用python写了个自动提交的程序,header加上自己的cooki

Training的第二十天

今天接着做前天的活,就是实现把下载下来的jpg格式的图片设置为桌面的功能.要实现这个功能的关键点一个是要调用API(SystemParametersInfo)更换桌面:二是要把下载下来的JPG格式的图片转换成Bmp格式的图片才能够应用为桌面. 由于对API没什么概念,所以我从网上查了下资料并从网上copy了有关该API变成C#的代码和把jpg格式的图片转换成bmp格式图片的代码.接着看懂了里面的代码便自己修改了一下.接下来的是完善这个程序和把它加入到windows自动启动的任务中. 对于程序的完

2014 Multi-University Training Contest 6 Apple Tree(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 120 Problem Description I've bought an orchard an

hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 188    Accepted Submission(s): 129 Problem Description I've bought an orchard an

xtu DP Training C.炮兵阵地

炮兵阵地 Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 118564-bit integer IO format: %lld      Java class name: Main 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表

2014 Super Training #1 F Passage 概率DP

原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排序,即P越大,Q越小就越好,这样可以确保先选最优的路走. dp[i][j]表示已经到了第i条路(说明前i-1条都没成功的情况),还剩j块钱时能够走出去的概率. 则方程: dp[i][j] = way[i].P + way[i].Q*(dp[i+1][j-1]) + way[i].D*(dp[i+1]

2014 UESTC Training for Data Structures H - Cookies Test

H - Cookies Test Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status As chief programmer at a cookie production plant you have many responsibilities, one of them being that the cookies produced and packag

2014 UESTC Training for Data Structures K - 方师傅与栈

K - 方师傅与栈 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅有一个1?N的排列,排列的顺序是固定的,他想要把这个排列重新排列成他喜欢的顺序. 于是他买了一个栈,他会按顺序将排列扔进栈内,在某些时刻将栈顶元素取出,这样出栈后的排列就可以重新排序啦. 例如,原序列是1,2,他先将1入栈,再将2入栈,然后将2出栈,最后将1出栈,那么新序列就变