codeforces 724
题目链接:
http://codeforces.com/contest/724
1 second
256 megabytes
standard input
standard output
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
monday
tuesday
NO
sunday
sunday
YES
saturday
tuesday
YES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=5e5+10;
string str1,str2;
int check(string s)
{
if(s=="monday")return 0;
else if(s=="tuesday")return 1;
else if(s=="wednesday")return 2;
else if(s=="thursday")return 3;
else if(s=="friday")return 4;
else if(s=="saturday")return 5;
else return 6;
}
int main()
{
cin>>str1>>str2;
int a=check(str1),b=check(str2);
int t=(b-a+7)%7;
if(28%7==t||30%7==t||31%7==t)printf("YES\n");
else printf("NO\n");
return 0;
}
/* 题意: 水; 思路:
水;
*/
2 seconds
256 megabytes
standard input
standard output
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.
Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
2 4
1 3 2 4
1 3 4 2
YES
4 4
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
NO
3 6
2 1 3 4 5 6
1 2 4 3 5 6
1 2 3 4 6 5
YES
#include <bits/stdc++.h>
using namespace std;
int n,m,a[23][23],num[23],flag=1;
int check(int x,int y)
{
for(int i=1;i<=n;i++)
{
int cnt=0;
for(int j=1;j<=m;j++)
{
if(j==x)
{
if(a[i][j]!=y)cnt++;
}
else if(j==y)
{
if(a[i][j]!=x)cnt++;
}
else
{
if(a[i][j]!=j)cnt++;
}
}
if(cnt>2)return 0;
}
return 1;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
{
num[i]=0;
for(int j=1;j<=m;j++)
{
if(a[i][j]!=j)num[i]++;
}
if(num[i]>4)
{
cout<<"NO";
return 0;
}
if(num[i]>2)flag=0;
}
if(flag)
{
cout<<"YES";
return 0;
}
flag=0;
for(int i=1;i<=m;i++)
{
for(int j=i+1;j<=m;j++)
{
if(check(i,j))flag=1;
}
}
if(flag)cout<<"YES";
else cout<<"NO";
return 0;
}
/* 题意: 每行交换最多一次,最后还可以交换两列,问最后每行是否都能变成1,2,...m的排列; 思路: 枚举最后要交换哪两列,然后判断每行是否能在一次变换中变成列交换之前的状态,还有判断不进行列交换的时候;
*/
2 seconds
256 megabytes
standard input
standard output
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle.
Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.
At the moment 0, from the point (0, 0) the laser ray is released in the direction of point (1, 1). The ray travels with a speed of
meters per second. Thus, the ray will reach the point (1, 1) in exactly one second after the start.
When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.
For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print - 1 for such sensors.
The first line of the input contains three integers n, m and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors.
Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.
Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or - 1 if this will never happen.
3 3 4
1 1
1 2
2 1
2 2
1
-1
-1
2
3 4 6
1 1
2 1
1 2
2 2
1 3
2 3
1
-1
-1
2
5
-1
7 4 5
1 3
2 2
5 1
5 3
4 3
13
2
9
5
-1
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=1e18;
const int maxn=1e5+5;
int k,fx[maxn],fy[maxn];
LL dir[4][2]={-1,1,-1,-1,1,1,1,-1};
LL tx[4],ty[4],n,m;
LL gcd(LL a,LL b,LL &x,LL &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
LL ans=gcd(b,a%b,x,y);
LL temp=x;
x=y;
y=temp-a/b*y;
return ans;
}
LL GCD(LL a,LL b)
{
if(!b)return a;
return GCD(b,a%b);
}
LL solve(LL fn,LL fm)
{
LL b=fm-fn;
LL x,y,d;
d=gcd(n,-m,x,y);
if(b%d!=0)return -1;
if(b%m==0)return fn;
LL lcm=abs(n*m/d);
x=x*(b/d);
LL ans=((x*n+fn)%lcm+lcm)%lcm;
if(ans==0)ans=lcm;
return ans;
}
int main()
{
scanf("%I64d%I64d%d",&n,&m,&k);
for(int i=1;i<=k;i++)scanf("%d%d",&fx[i],&fy[i]);
LL hi=n/GCD(n,m)*m;
n*=2;m*=2;
for(int i=1;i<=k;i++)
{
LL ans=inf;
for(int j=0;j<4;j++)
{
LL temp=solve(fx[i]*dir[j][0],fy[i]*dir[j][1]);
if(temp>0&&temp<=hi)ans=min(ans,temp);
}
if(ans==inf)printf("-1\n");
else printf("%I64d\n",ans);
}
return 0;
}
/*
题意:
给出一束光从(0,0)出发,一直到角落才会停,问光到达给出的这些点的最短时间是多少; 思路: 可以发现这些点在平面上镜面对称后得到的点是(2*k*n+-x,2*t*m+-y);然后坐标相等,就是解同余方程了;
范围在(0,lcm(n,m))才是正确的;
*/
2 seconds
256 megabytes
standard input
standard output
You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.
Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j, j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.
Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.
Find the lexicographically smallest string, that can be obtained using this procedure.
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).
The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
3
cbabc
a
2
abcab
aab
3
bcabcbaccba
aaabb
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int m;
char s[maxn],ans[maxn],tep[maxn];
int main()
{
scanf("%d",&m);
scanf("%s",s);
int len=strlen(s),cnt,num;
for(int i=len-1;i>=0;i--)s[i+1]=s[i];
for(char temp='a';temp<='z';temp++)
{
int p=0,flag=1,fp=0;num=0;
for(int i=1;i<=len;i++)
{
if(i<=p+m)
{
if(s[i]<temp)tep[num++]=s[i],p=i;
else if(s[i]==temp)fp=i;
}
else
{
if(fp>p)
{
tep[num++]=s[fp],p=fp;i--;
}
else {flag=0;break;}
}
}
if(flag)
{
for(int i=0;i<num;i++)ans[i]=tep[i];
cnt=num;
break;
}
}
if(cnt==0)
{
char d='z';
for(int i=1;i<=len;i++)d=min(d,s[i]);
cnt=1;
ans[0]=d;
}
sort(ans,ans+cnt);
for(int i=0;i<cnt;i++)printf("%c",ans[i]);
return 0;
}
/*
题意:
每隔m个字符选一个,使得选中的这些字符排序后字典序最小; 思路: 枚举最大的那个字符,遍历一遍,比其小的全要,相等的要当前范围最后一个;
*/
codeforces 724的更多相关文章
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- Codeforces 724 E Goods transportation
Description 有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流. Sol DP. 这种特殊的图可以DP,把最大流转化成最小割. 最小割 ...
- 刷题记录:Codeforces Round #724 (Div. 2)
Codeforces Round #724 (Div. 2) 20210713.网址:https://codeforces.com/contest/1536. div2明显比div3难多了啊-只做了前 ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)
题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...
- Codeforces 724E Goods transportation(最小割转DP)
[题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...
- 【codeforces 724E】Goods transportation
[题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- yii2.0用户登录,退出判断(摘录)
文章来源:http://blog.sina.com.cn/s/blog_88a65c1b0101ix13.html 判断用户是否登录 在 Yii2.0 里面,判断用户是否已经登录,我们用下面的代码即可 ...
- Scala on Visual Studio Code
Download and install Scala Download a scala installation package from here. Then install it. Linux s ...
- Failed to install on device ‘emulator-5554′: timeout
启动android模拟器时候如果提示:Failed to install on device ‘emulator-5554′: timeout 这是可能因为卡的原因导致启动超时,解决办法:eclips ...
- C#生成条形码 Code128算法
条形有很多种,Code128是比较常用的一种,是一种高密度条码, CODE128 码可表示从 ASCII 0 到ASCII 127 共128个字符,故称128码.其中包含了数字.字母和符号字符. Co ...
- SVG基础图形与参数
SVG是什么 SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用来定义WEB上使用的矢量图 SVG 使用 XML 格式定义图形 SVG 图像在缩放时其图形质量不 ...
- virtualbox迁移至vcenter/vmware workstation
参考文献: http://www.itsecurenet.com/virtualbox-ova-to-vsphere-ovf/ http://www.techrepublic.com/blog/win ...
- wxPython简单入门
wxPython简介 wxPython 是 Python 语言的一套优秀的 GUI 图形库,允许 Python 程序员很方便的创建完整的.功能键全的 GUI 用户界面. wxPython 是作为优秀 ...
- 【读书笔记】iOS-使用应用内支付注意事项
一,iOS端开发. 如果购买成功,我们需要将凭证发送到服务器上进行验证.考虑到网络异常情况,iOS端的发送凭证操作应该可以持久化,如果程序退出,崩溃或网络异常,可以恢复重试. 二,服务器端开发. 服务 ...
- UITabBarController QQ
AppDelegate.m #import "AppDelegate.h" #import "FirstViewController.h" #import &q ...
- IOS MenuController初步了解
IOS MenuController初步了解 默认情况下有以下控件已经支持MenuController. UITextField UITextView UIWebView 让其他控件也支持MenuCo ...